First DOM-capable vitest lane for the repo: default env stays node (pure lib helpers), a test opts into jsdom per-file with a // @vitest-environment jsdom docblock; plugin-react wired for JSX/hook tests. Adds jsdom + @testing-library/react devDeps and 3 back-ladder tests (LIFO peel, stacks over useBackToClose, inactive layer is transparent) driven by direct popstate dispatch — deterministic, no dependency on jsdom's async back(). Closes the deferred R2 component-test gap (useBackToExit).
20 lines
1005 B
TypeScript
20 lines
1005 B
TypeScript
import { defineConfig } from "vitest/config";
|
|
import react from "@vitejs/plugin-react";
|
|
|
|
// Unit + component/hook tests, deliberately separate from vite.config.ts so the production build
|
|
// never has to load vitest. The DEFAULT environment is node (the pure src/lib helpers — fast, no
|
|
// DOM). A test that needs the DOM (component render or renderHook) opts INTO jsdom per-file with a
|
|
// // @vitest-environment jsdom
|
|
// docblock on its first line. plugin-react is wired here so those tests get JSX + a Fast-Refresh-
|
|
// free React transform; it is a no-op for the plain .ts node tests (they carry no JSX). jsdom is a
|
|
// devDependency referenced only via that docblock env string — knip's vitest plugin still sees it.
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
test: {
|
|
// .tsx included on purpose: a test file the glob misses does not fail, it is simply never
|
|
// collected, and the gate still prints green.
|
|
include: ["src/**/*.test.{ts,tsx}"],
|
|
environment: "node",
|
|
},
|
|
});
|