import { defineConfig } from "vitest/config"; import path from "node:path"; // React only exposes `act` in its development build, so a shell with // NODE_ENV=production would break every component test. Vitest only sets // NODE_ENV when it is unset, so force it. // // Next's `next/types/global` declares NODE_ENV on ProcessEnv as `readonly`, // so a plain `process.env.NODE_ENV = "test"` fails the type check that // `next build` runs over this file (tsconfig includes **/*.ts) and takes // the whole deployment down. Object.assign has no source-to-target // assignability constraint, so it compiles while still writing the value // through process.env's setter at runtime. Object.assign(process.env, { NODE_ENV: "test" }); export default defineConfig({ resolve: { alias: [ { find: "@", replacement: path.resolve(__dirname, "./src") }, // The `server-only` package ships inside Next.js' compiled dependencies // and cannot be resolved by Vitest; point it at an empty stand-in. { find: /^server-only$/, replacement: path.resolve(__dirname, "./src/test-support/server-only.ts") }, ], }, test: { environment: "node", include: ["src/**/*.test.{ts,tsx}"], // The PDF/PNG split test shells out to poppler; it takes a few seconds on // its own and times out when the whole suite runs in parallel. testTimeout: 15000, }, });