MEGAINFRA-WEBAPP/vitest.config.ts
DEls ca7d6c94e3 fix(build): unbreak next build type check on vitest NODE_ENV
The deployment failed at "Running TypeScript ..." with:

  vitest.config.ts(7,13): error TS2540: Cannot assign to 'NODE_ENV'
  because it is a read-only property.

Next's next/types/global declares NODE_ENV on ProcessEnv as `readonly`.
tsconfig includes **/*.ts, so next build type-checks vitest.config.ts and
the direct assignment from 34017d8 took every deploy down with it.

Object.assign has no source-to-target assignability constraint, so it
compiles while still writing NODE_ENV through process.env's setter —
React still gets its development build, which is what exposes `act`.

Verified: tsc --noEmit clean, 3839 tests pass, npm run build succeeds.
2026-10-26 02:22:44 +02:00

32 lines
1.3 KiB
TypeScript

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,
},
});