vitest.e2e.config.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import tsconfigPaths from 'vite-tsconfig-paths'
  2. import { defineConfig } from 'vitest/config'
  3. // Real-API suite, separate because it spends tokens. Each test self-skips without
  4. // its provider credential for keyless CI; credentialed workflows preflight the
  5. // secrets they require. Values may come from the environment or gitignored root
  6. // `.env`, with provider-specific endpoint overrides where supported.
  7. try {
  8. // Node >= 21.7 native; throws when the file does not exist.
  9. process.loadEnvFile(new URL('.env', import.meta.url).pathname)
  10. } catch {
  11. // No .env — fine, the environment may already carry the variables.
  12. }
  13. const DEFAULT_E2E_MAX_WORKERS = 4
  14. function positiveIntFromEnv(name: string, fallback: number): number {
  15. const raw = process.env[name]
  16. if (raw === undefined || raw === '') return fallback
  17. const value = Number(raw)
  18. if (!Number.isInteger(value) || value < 1) {
  19. throw new Error(`${name} must be a positive integer, got ${JSON.stringify(raw)}`)
  20. }
  21. return value
  22. }
  23. const e2eMaxWorkers = positiveIntFromEnv('DSH_E2E_MAX_WORKERS', DEFAULT_E2E_MAX_WORKERS)
  24. export default defineConfig({
  25. // Same resolution note as vitest.config.ts: bare workspace names resolve
  26. // through the root tsconfig paths map; the native option cannot do this.
  27. plugins: [tsconfigPaths({ projects: ['./tsconfig.json'] })],
  28. test: {
  29. include: ['packages/*/*/tests/**/*.e2e.ts', 'examples/*/tests/**/*.e2e.ts'],
  30. // Real model calls: generous timeouts, and retries for transient flakes
  31. // (the shared internal key hits concurrency quotas). No coverage — the
  32. // unit suites own the coverage gate.
  33. testTimeout: 120_000,
  34. hookTimeout: 30_000,
  35. retry: 2,
  36. // Run files in a bounded pool: enough lower-level parallelism to keep CI
  37. // and local with-key runs moving, while leaving a resource knob for shared
  38. // API quotas (`DSH_E2E_MAX_WORKERS=1` restores serial execution).
  39. fileParallelism: e2eMaxWorkers > 1,
  40. maxWorkers: e2eMaxWorkers,
  41. },
  42. })