import { fileURLToPath } from "node:url"; import react from "@vitejs/plugin-react"; import { defineConfig } from "vitest/config"; export default defineConfig({ plugins: [react()], resolve: { // Resolves the "@/*" path alias from tsconfig.json. tsconfigPaths: true, alias: { // The real package throws unless bundled for React Server Components. "server-only": fileURLToPath(new URL("./test/server-only.ts", import.meta.url)), }, }, test: { // Server code runs in Node; component tests opt in with `// @vitest-environment jsdom`. environment: "node", include: ["src/**/*.test.{ts,tsx}", "scripts/**/*.test.ts", "cli/**/*.test.ts"], restoreMocks: true, unstubEnvs: true, coverage: { provider: "v8", include: ["src/**/*.{ts,tsx}"], exclude: [ "src/**/*.test.{ts,tsx}", "src/**/*.d.ts", // Async Server Component: unit runners can't render it (Next docs, testing/vitest.md). "src/app/page.tsx", ], reporter: ["text", "json-summary"], // vrek principle pri-be2smzk: `npm run coverage` fails if line coverage drops below 95%. thresholds: { lines: 95 }, }, }, });