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 gets its own throwaway Postgres database and its own // dedicated PrismaClient, wired up via a `vi.mock("@/lib/prisma", ...)` // factory in tests/setup.ts (not by mutating the ambient // process.env.DATABASE_URL, which used to be shared/racy across files — // see the long comment at the top of tests/setup.ts for the history). // With no mutable state shared between files, parallel file execution // (Vitest's default) is safe again. }, });