vitest.e2e.config.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 tsconfig.base.json paths facade (no include = match-all, so
  27. // client-package sources get mapping too — dropping /client subpath imports
  28. // onto package exports would load browser dist bundles into node).
  29. // Built-artifact e2e suites are unaffected: their built-ness lives in
  30. // subprocesses and createRequire lookups, which bypass vite resolution
  31. // entirely.
  32. plugins: [tsconfigPaths({ projects: ['./tsconfig.base.json'] })],
  33. test: {
  34. setupFiles: ['./scripts/test-invariants.ts'],
  35. // apps/cli only, not apps/*: apps/web/tests/*.e2e.ts needs the built
  36. // frontend dist and runs under vitest.web.config.ts (the test:web job).
  37. include: ['packages/*/*/tests/**/*.e2e.ts', 'apps/cli/tests/**/*.e2e.ts', 'examples/*/tests/**/*.e2e.ts'],
  38. // Real model calls: generous timeouts, and retries for transient flakes
  39. // (the shared internal key hits concurrency quotas). No coverage — the
  40. // unit suites own the coverage gate.
  41. testTimeout: 120_000,
  42. hookTimeout: 30_000,
  43. retry: 2,
  44. // Run files in a bounded pool: enough lower-level parallelism to keep CI
  45. // and local with-key runs moving, while leaving a resource knob for shared
  46. // API quotas (`DSH_E2E_MAX_WORKERS=1` restores serial execution).
  47. fileParallelism: e2eMaxWorkers > 1,
  48. maxWorkers: e2eMaxWorkers,
  49. },
  50. })