import { defineConfig } from "vitest/config"; import react from "@vitejs/plugin-react"; import tsconfigPaths from "vite-tsconfig-paths"; // Setting TEST_DATABASE_URI forces the legacy single-database serial mode // (bisect hatch): shared db, truncate per run, no forks and no clones. const serialMode = Boolean(process.env.TEST_DATABASE_URI); const maxForks = Number(process.env.VITEST_MAX_FORKS ?? 8); export default defineConfig({ plugins: [tsconfigPaths(), react()], test: { // Node by default; component specs opt into jsdom with a // `// @vitest-environment jsdom` docblock. environment: "node", setupFiles: ["./vitest.setup.ts", "./tests/vitest-worker-setup.ts"], include: ["tests/int/**/*.int.spec.ts"], globalSetup: ["./tests/vitest-global.ts"], reporters: ["default", "./tests/vitest-reporter.ts"], ...(serialMode ? { fileParallelism: false } : { // Per-fork worker databases (tests/vitest-worker-setup.ts) replace // the old serial execution: cross-file data interference is gone by // construction because two forks never share tables. Fork cap stays // conservative: Postgres max_connections=100 on this box plus IO. // // isolate:false is load-bearing, not just an optimization: the // Vitest 4 pool scheduler REUSES fork processes only between // non-isolated tasks (cli-api schedule()), and module/instance // persistence across files is what lets tests/helpers/ // get-test-payload.ts memoize the Payload boot. Per-file // state-leak risk is blunted by the afterEach cleanup harness in // vitest.setup.ts; specs that still misbehave opt out by booting // their own payload instance (see helper docstring). fileParallelism: true, pool: "forks" as const, isolate: false, maxWorkers: maxForks, }), }, });