Migrate frontend tests from node:test to Vitest#291
Conversation
Frontend was the only package on node --experimental-strip-types with a custom resolve-hooks.mjs loader that resolved workspace deps to stale dist/. strip-types is not a transpiler, so the runtime test channel could not resolve workspace packages to source (parameter properties, directory imports, antlr CJS interop all broke). slides/docs/sheets already run on Vitest. Vitest reuses frontend's existing vite.config.ts — its aliases already point @wafflebase/* at src/index.ts, and its react plugin + antlr assert shim + jsdom handle JSX/CJS/DOM. So a workspace src edit is now visible to pnpm frontend test with no rebuild, killing the stale-dist runtime false-failure class, and resolve-hooks.mjs + register-hooks.mjs (incl. hand-written virtual stubs) are deleted. Test bodies were converted with a throwaway jscodeshift codemod (assert.*->expect, node:test->vitest, mock.fn->vi.fn, mock call-args indexing, leading-comment preservation) across 42 .test.ts files; .integration.ts (separate tsx lane) untouched. Parity: 399 passed / 0 failed (skip-count differs by runner convention). verify:fast green. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR replaces the Node.js built-in test runner with Vitest across the entire frontend test suite. It reconfigures Vite to enable jsdom testing, removes 250 lines of custom ESM resolve/load hooks, updates helper documentation to reflect the new test isolation approach, and migrates ~50 test files from ChangesFrontend test runner migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
|
Verification: verify:selfResult: ✅ PASS in 240.0s
Verification: verify:integrationResult: ✅ PASS |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Both tasks' work has landed on main: the Vitest migration merged as #291, and the @wafflebase/tokens deploy fixes (publish-ghpage.yml build:all + Dockerfile tokens build) are present on main, absorbed into #292. Their only open todo items were trailing 'open PR / code review' process steps, now ticked, so pnpm tasks:archive moves both to archive/2026/05 and regenerates the index. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
The frontend package was the only one running tests on
node --experimental-strip-typeswith a bespokeresolve-hooks.mjsloaderthat resolved workspace deps to stale
dist/(preferring built output,with hand-written virtual stubs). Because strip-types is not a transpiler
(it can't handle TS parameter properties, directory imports, or antlr CJS
interop), the runtime test channel could not resolve
@wafflebase/*tosource — so a
srcedit was invisible topnpm frontend testuntil arebuild, producing the recurring stale-
dist/"missing export" failures.This migrates the frontend to Vitest, like
slides/docs/sheets:vite.config.ts— itsresolve.aliasalreadypoints
@wafflebase/{sheets,docs,slides}atsrc/index.ts, and its Reactplugin + antlr
assert-shim + jsdom handle JSX/CJS/DOM. So workspace depsnow resolve to source with no rebuild, killing the stale-
dist/runtime false-failure class.
resolve-hooks.mjs+register-hooks.mjs(250+ lines, incl. virtualstubs) are deleted; net change is −100ish lines.
.test.tsfiles convertednode:test/assert→vitest/expectvia a throwaway jscodeshift codemod (~1,100 assertions;
mock.fn→vi.fn,leading comments preserved). The
.integration.tslane (separatetsx --testglob) is untouched.test→vitest --run,test:watch→vitest; addsvitest/jsdom/@vitest/coverage-v8devDeps.Design + constraints:
docs/design/cross-package-source-resolution.md(added in a sibling PR).
Test plan
pnpm frontend test— 399 passed / 0 failed (parity with thenode:test baseline; skip count differs only by runner convention)
pnpm frontend lintclean (--max-warnings 0)pnpm verify:fastexit 0slides/src(absent fromdist)is visible to
pnpm frontend testwith no rebuild — the case thatfailed under
dist-first resolution🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Chores