vitest.integration.config.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import path from "node:path";
  2. import { defineConfig } from "vitest/config";
  3. export default defineConfig({
  4. test: {
  5. globals: true,
  6. environment: "node",
  7. setupFiles: ["./tests/setup.ts"],
  8. api: {
  9. host: process.env.VITEST_API_HOST || "127.0.0.1",
  10. port: Number(process.env.VITEST_API_PORT || 51204),
  11. strictPort: false,
  12. },
  13. open: false,
  14. testTimeout: 20000,
  15. hookTimeout: 20000,
  16. maxConcurrency: 5,
  17. pool: "threads",
  18. // 仅运行"需要数据库"的集成测试(避免把所有重依赖测试默认跑进 CI)
  19. // 说明:包括 tests/integration/ 目录和从主配置排除的需要 DB 的 API 测试
  20. include: [
  21. "tests/integration/webhook-targets-crud.test.ts",
  22. "tests/integration/notification-bindings.test.ts",
  23. "tests/integration/auth.test.ts",
  24. "tests/integration/provider-endpoint-sync-race.test.ts",
  25. // 需要 DB 的 API 测试(从主配置排除,在此运行)
  26. "tests/api/users-actions.test.ts",
  27. "tests/api/providers-actions.test.ts",
  28. "tests/api/keys-actions.test.ts",
  29. "tests/api/my-usage-readonly.test.ts",
  30. ],
  31. exclude: ["node_modules", ".next", "dist", "build", "coverage", "**/*.d.ts"],
  32. reporters: ["verbose"],
  33. isolate: true,
  34. mockReset: true,
  35. restoreMocks: true,
  36. clearMocks: true,
  37. resolveSnapshotPath: (testPath, snapExtension) => {
  38. return testPath.replace(/\.test\.([tj]sx?)$/, `${snapExtension}.$1`);
  39. },
  40. },
  41. resolve: {
  42. alias: {
  43. "@": path.resolve(__dirname, "./src"),
  44. "server-only": path.resolve(__dirname, "./tests/server-only.mock.ts"),
  45. },
  46. },
  47. });