import { defineConfig } from "vitest/config"; import path from "node:path"; export default defineConfig({ resolve: { alias: { "@": path.resolve(__dirname, "./src"), }, }, test: { environment: "node", // Scope explicitly to this repo's own tests/ dir — without this, Vitest's // default glob also picks up any stray sibling git worktree checked out // under .claude/worktrees/ (e.g. worktree-ui-basic), which isn't excluded // by Vitest's defaults since those only skip node_modules/.git/etc, not // .claude/. A stray worktree's stale test file still resolves the "@" // alias to *this* repo's src/ (see resolve.alias above, which is // __dirname-relative), so it silently runs old tests against current // code under a shared identity — confirmed happening in practice once a // second worktree existed. include: ["tests/**/*.test.ts"], setupFiles: ["./tests/setup.ts"], // Each test file spins up its own throwaway Postgres database by // mutating process.env.DATABASE_URL in tests/setup.ts's beforeAll (see // that file). That per-file DB switch is not safe under Vitest's default // parallel file execution: two files' beforeAll/query timing can // interleave such that both end up issuing real queries against the // same throwaway DB (confirmed empirically once Request gained a real // FK to Employee — tests/employees.test.ts and tests/requests.test.ts // started intermittently deleting/reading each other's rows, causing // spurious FK-violation and row-count failures that disappear when run // sequentially). Disabling file parallelism trades a bit of wall-clock // test time for correctness — each file's throwaway DB is now genuinely // private for the duration of that file's run. fileParallelism: false, }, });