import path from "node:path"; import { defineConfig, mergeConfig } from "vitest/config"; import viteConfig from "./vite.config"; import { resolveMaxWorkers } from "./scripts/vitest-worker-budget"; if (process.env.DEBUG === "1") process.env.DEBUG = ""; // Pins NODE_ENV=test — see apps/web/AGENTS.md "Testing notes" for why this is load-bearing. process.env.NODE_ENV = "test"; const configuredMaxWorkers = process.env.VITEST_MAX_WORKERS?.trim(); const isCI = Boolean(process.env.CI); const allowUnsafeParallelism = process.env.KANDEV_ALLOW_UNSAFE_TEST_PARALLELISM === "1"; const maxWorkers = resolveMaxWorkers(configuredMaxWorkers, isCI, allowUnsafeParallelism); if (configuredMaxWorkers && !isCI && !allowUnsafeParallelism) { delete process.env.VITEST_MAX_WORKERS; } export default mergeConfig( viteConfig, defineConfig({ resolve: { alias: [ { find: /^monaco-editor$/, replacement: path.resolve(__dirname, "vitest.monaco-editor.ts"), }, ], }, test: { environment: "happy-dom", environmentOptions: { happyDOM: { settings: { navigation: { disableMainFrameNavigation: true, disableChildFrameNavigation: true, }, }, }, }, setupFiles: ["./vitest.setup.ts"], // `e2e/**/*.spec.ts` belongs to Playwright, but plain unit tests for the // e2e helpers themselves (`*.test.ts`) still run here — excluding the // whole tree would let them sit in the repo without ever executing. exclude: ["e2e/**/*.spec.ts", "e2e/fixtures/**", "e2e/pages/**", "node_modules/**"], pool: "threads", maxWorkers, // Already the default, pinned because it is load-bearing: a run that // collects nothing must exit non-zero rather than read as a green suite. passWithNoTests: false, }, }), );