test(history): jsdom/renderHook lane + useBackToExit back-ladder tests

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).
This commit is contained in:
2026-08-06 23:25:06 +02:00
parent d6d33a188d
commit 60fcc4f5f0
4 changed files with 979 additions and 7 deletions
+10 -7
View File
@@ -1,15 +1,18 @@
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
// Unit tests for the pure helpers in src/lib — deliberately separate from vite.config.ts so the
// production build never has to load vitest. Plain node env (no jsdom): these tests stub the
// modules that touch the DOM. Browser flows stay in e2e/ under Playwright (`siftlode e2e`).
// Being its own file means vite.config.ts is NOT merged in — a future test that renders a .tsx
// component has to wire @vitejs/plugin-react (and a DOM environment) here itself.
// 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. (Such a test must still wire plugin-react +
// a DOM environment here — see above — but at least it will run and say so.)
// collected, and the gate still prints green.
include: ["src/**/*.test.{ts,tsx}"],
environment: "node",
},