vitest.e2e.config.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import tsconfigPaths from 'vite-tsconfig-paths'
  2. import { defineConfig } from 'vitest/config'
  3. // Real-API end-to-end tests: `pnpm run test:e2e`, file pattern *.e2e.ts.
  4. // Separate from the default suite (`pnpm run test`, *.spec.ts) on purpose —
  5. // these hit the live DeepSeek API, spend tokens, and need a key.
  6. //
  7. // Secrets: tests gate themselves with
  8. // `describe.skipIf(!process.env.DEEPSEEK_API_KEY)`, so the suite passes
  9. // (all-skipped) without credentials. The keyless CI workflow relies on that;
  10. // the real-API workflow preflights the secret and fails loudly if it is absent.
  11. // Put the key in the environment or in a gitignored `.env` at the repo root:
  12. //
  13. // DEEPSEEK_API_KEY=sk-…
  14. // DEEPSEEK_BASE_URL=https://… # optional, defaults to the public API
  15. try {
  16. // Node >= 21.7 native; throws when the file does not exist.
  17. process.loadEnvFile(new URL('.env', import.meta.url).pathname)
  18. } catch {
  19. // No .env — fine, the environment may already carry the variables.
  20. }
  21. const DEFAULT_E2E_MAX_WORKERS = 4
  22. function positiveIntFromEnv(name: string, fallback: number): number {
  23. const raw = process.env[name]
  24. if (raw === undefined || raw === '') return fallback
  25. const value = Number(raw)
  26. if (!Number.isInteger(value) || value < 1) {
  27. throw new Error(`${name} must be a positive integer, got ${JSON.stringify(raw)}`)
  28. }
  29. return value
  30. }
  31. const e2eMaxWorkers = positiveIntFromEnv('DSH_E2E_MAX_WORKERS', DEFAULT_E2E_MAX_WORKERS)
  32. export default defineConfig({
  33. // Same resolution note as vitest.config.ts: bare workspace names resolve
  34. // through the root tsconfig paths map; the native option cannot do this.
  35. plugins: [tsconfigPaths({ projects: ['./tsconfig.json'] })],
  36. test: {
  37. include: ['packages/*/*/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. })