diff --git a/package.json b/package.json index 0ab1e41b..14623c0e 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "scripts": { "build": "pnpm --filter vinext run build", "test": "vitest run", + "test:unit": "vitest run --project unit", + "test:integration": "vitest run --project integration", "test:watch": "vitest", "generate:google-fonts": "node scripts/generate-google-fonts.js", "typecheck": "tsgo --noEmit", diff --git a/vitest.config.ts b/vitest.config.ts index c1c376aa..29c03a1e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,24 +1,62 @@ import { randomUUID } from "node:crypto"; import { defineConfig } from "vitest/config"; +/** + * Integration test files that spin up Vite dev servers against shared fixture + * directories. These must run serially to avoid Vite deps optimizer cache + * races (node_modules/.vite/*) that produce "outdated pre-bundle" 500s. + * + * When adding a new test file that calls startFixtureServer(), createServer() + * from Vite, or spawns a dev server subprocess, add it here. + */ +const integrationTests = [ + "tests/app-router.test.ts", + "tests/pages-router.test.ts", + "tests/features.test.ts", + "tests/cjs.test.ts", + "tests/ecosystem.test.ts", + "tests/static-export.test.ts", + "tests/postcss-resolve.test.ts", + "tests/nextjs-compat/**/*.test.ts", +]; + +// GitHub Actions reporter adds inline failure annotations in PR diffs. +const reporters: string[] = process.env.CI + ? ["default", "github-actions"] + : ["default"]; + +const env = { + // Mirrors the Vite `define` in index.ts that inlines a build-time UUID. + // Setting it here means tests exercise the same code path as production. + __VINEXT_DRAFT_SECRET: randomUUID(), +}; + export default defineConfig({ test: { - include: ["tests/**/*.test.ts"], - testTimeout: 30000, - env: { - // Mirrors the Vite `define` in index.ts that inlines a build-time UUID. - // Setting it here means tests exercise the same code path as production. - __VINEXT_DRAFT_SECRET: randomUUID(), - }, - // Multiple suites spin up Vite dev servers against the same fixture dirs. - // Running test files in parallel can race on Vite's deps optimizer cache - // (node_modules/.vite/*) and produce "outdated pre-bundle" 500s. + reporters, + // fileParallelism is a global setting in vitest 3.x (cannot be set + // per-project). Integration tests need serial execution, so we keep + // it disabled globally. The win from the project split is that + // `vitest run --project unit` lets you skip integration tests entirely + // for a fast feedback loop (~seconds vs ~2 minutes). fileParallelism: false, - // GitHub Actions reporter adds inline failure annotations in PR diffs. - // It's auto-enabled with the default reporter, but being explicit ensures - // it survives any future reporter config changes. - reporters: process.env.CI - ? ["default", "github-actions"] - : ["default"], + projects: [ + { + test: { + name: "unit", + include: ["tests/**/*.test.ts"], + exclude: integrationTests, + env, + }, + }, + { + test: { + name: "integration", + include: integrationTests, + testTimeout: 30000, + env, + }, + }, + ], }, });