vitest.e2e.config.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import tsconfigPaths from 'vite-tsconfig-paths'
  2. import { defineConfig } from 'vitest/config'
  3. import { standardDecoratorPlugin, vitestExecArgv } from './vitest.shared.ts'
  4. // Real-API suite, separate because it spends tokens. Each test self-skips without
  5. // its provider credential for keyless CI; credentialed workflows preflight the
  6. // secrets they require. Values may come from the environment or gitignored root
  7. // `.env`, with provider-specific endpoint overrides where supported.
  8. try {
  9. // Node >= 21.7 native; throws when the file does not exist.
  10. process.loadEnvFile(new URL('.env', import.meta.url).pathname)
  11. } catch {
  12. // No .env — fine, the environment may already carry the variables.
  13. }
  14. const DEFAULT_E2E_MAX_WORKERS = 4
  15. function positiveIntFromEnv(name: string, fallback: number): number {
  16. const raw = process.env[name]
  17. if (raw === undefined || raw === '') return fallback
  18. const value = Number(raw)
  19. if (!Number.isInteger(value) || value < 1) {
  20. throw new Error(`${name} must be a positive integer, got ${JSON.stringify(raw)}`)
  21. }
  22. return value
  23. }
  24. const e2eMaxWorkers = positiveIntFromEnv('DSH_E2E_MAX_WORKERS', DEFAULT_E2E_MAX_WORKERS)
  25. export default defineConfig({
  26. // Same resolution note as vitest.config.ts: bare workspace names resolve
  27. // through the tsconfig.base.json paths facade (no include = match-all, so
  28. // client-package sources get mapping too — dropping /client subpath imports
  29. // onto package exports would load browser dist bundles into node).
  30. // Built-artifact e2e suites are unaffected: their built-ness lives in
  31. // subprocesses and createRequire lookups, which bypass vite resolution
  32. // entirely.
  33. plugins: [tsconfigPaths({ projects: ['./tsconfig.base.json'] }), standardDecoratorPlugin()],
  34. test: {
  35. execArgv: vitestExecArgv,
  36. setupFiles: ['./scripts/test-proxy-environment.ts', './scripts/test-invariants.ts'],
  37. // apps/cli only, not apps/*: apps/web/tests/*.e2e.ts needs the built
  38. // frontend dist and runs under vitest.web.config.ts (the test:web job).
  39. include: ['packages/*/*/tests/**/*.e2e.ts', 'apps/cli/tests/**/*.e2e.ts'],
  40. exclude: [
  41. '**/*.expected.e2e.ts',
  42. 'packages/experimental/inspector/tests/client-browser.e2e.ts',
  43. ],
  44. // Real model calls: generous timeouts, and retries for transient flakes
  45. // (the shared internal key hits concurrency quotas). No coverage — the
  46. // unit suites own the coverage gate.
  47. testTimeout: 120_000,
  48. hookTimeout: 30_000,
  49. retry: 2,
  50. // Run files in a bounded pool: enough lower-level parallelism to keep CI
  51. // and local with-key runs moving, while leaving a resource knob for shared
  52. // API quotas (`DSH_E2E_MAX_WORKERS=1` restores serial execution).
  53. fileParallelism: e2eMaxWorkers > 1,
  54. maxWorkers: e2eMaxWorkers,
  55. },
  56. })