vitest.e2e.config.ts 2.3 KB

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