Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
70 changes: 54 additions & 16 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
],
},
});
Loading