vitest.e2e.config.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. setupFiles: ['./scripts/test-invariants.ts'],
  30. include: ['packages/*/*/tests/**/*.e2e.ts', 'examples/*/tests/**/*.e2e.ts'],
  31. // Real model calls: generous timeouts, and retries for transient flakes
  32. // (the shared internal key hits concurrency quotas). No coverage — the
  33. // unit suites own the coverage gate.
  34. testTimeout: 120_000,
  35. hookTimeout: 30_000,
  36. retry: 2,
  37. // Run files in a bounded pool: enough lower-level parallelism to keep CI
  38. // and local with-key runs moving, while leaving a resource knob for shared
  39. // API quotas (`DSH_E2E_MAX_WORKERS=1` restores serial execution).
  40. fileParallelism: e2eMaxWorkers > 1,
  41. maxWorkers: e2eMaxWorkers,
  42. },
  43. })