Repository navigation
test: test-page harness (TH1) (@miodec) - #8529
Conversation
Mounts the real TestPage and engine in jsdom on fake timers, types through the words input, advances frames, and reads word/letter states, phase and live stats. Own vitest project (no global DOM query mocks). Typing driver moved to dev/typing-driver.ts, shared with __mt, plus compose for IME input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NZNRfGDYsGYMUTp2zYUTrv
The test-page project included one spec file, so a new spec on the harness would land in the jsx project (mocked DOM queries) and fail obscurely. Specs on it are now named *.page-spec.tsx, and the harness throws if it loads with the mocked DOM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NZNRfGDYsGYMUTp2zYUTrv
test-helpers.ts only fed window.__mt once typing moved to the shared typing driver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NZNRfGDYsGYMUTp2zYUTrv
There was a problem hiding this comment.
🔵 Needs a closer look
It is net-new foundational test infrastructure whose correctness hinges on intricate fake-timer/animejs/router orchestration that cannot be fully validated by static review, warranting human sign-off even though no concrete defects were found.
No open issues 🎉
What changed in this PR
Roadmap step TH1: introduces a jsdom test-page harness that mounts the real TestPage + test engine, types through the real words input (keydown/beforeinput/input/keyup, plus IME composition), advances fake timers/animation frames, and reads back semantic word/letter states, test phase, and live stats. This is the safety net that later critical-path test-page steps (T1 onward) depend on. The only app code touched is dev-only (__mt typing helpers moved to a shared module and a new compose helper).
Changes:
- New
test-pagevitest project (*.page-spec.tsx, no DOM mocks) plus the harness (test-page.tsx) and a 17-spec starter suite. - Moved
typeChar/typeTextfromdev/test-helpers.tsinto newdev/typing-driver.tsand added IMEcompose, shared bywindow.__mtand the harness. - Extended
mock-staticto serve language JSON from disk, and updated roadmap/spec/agent docs.
| File | Description |
|---|---|
frontend/vitest.config.ts |
Adds the test-page project scoped to *.page-spec.tsx with jsdom and no mock-dom. |
frontend/src/ts/dev/typing-driver.ts |
New shared module: moved typeChar/typeText and new compose (IME) driver. |
frontend/src/ts/dev/test-helpers.ts |
Removes the moved typing helpers; remaining imports still used. |
frontend/src/ts/dev/expose.ts |
Imports typeText/compose from the new driver and exposes compose on __mt. |
frontend/__tests__/__harness__/test-page.tsx |
The harness: mounts real TestPage/engine, fake timers, mocks, state readers. |
frontend/__tests__/components/pages/test/TestPage.page-spec.tsx |
Starter suite of 17 specs exercising the harness. |
frontend/__tests__/__harness__/mock-static.ts |
Adds getLanguage/getCurrentLanguage reading /languages/*.json from disk. |
docs/specs/solid-monkeytype/spec.md |
Points the test-page harness bullet at the new file. |
docs/specs/solid-monkeytype/roadmap.md |
Marks TH1 done and updates dependent T1/T2 rows. |
docs/AGENT_BROWSER.md |
Documents the new __mt.compose helper. |
Review effort: Balanced
# Conflicts: # frontend/src/ts/dev/expose.ts
Summary
Roadmap step TH1: a jsdom harness that mounts the real TestPage and test engine, types through the words input, and reads what's rendered. It's the safety net for T1 onward.
wordsgives the test known text (via custom mode);configoverrides settings.Date.now/rAF it finds on import.data-ui-statewill use. T1 then only changes how the harness finds elements; the specs stay as they are.*.page-spec.tsxruns in its own project without the global DOM query mocks. If the harness loads under the mocks, it throws and tells you how to name the spec.__mt.compose(updates)is new (documented in AGENT_BROWSER.md).test-helpers.tsis gone: its remaining helpers only fed__mt, so they now live inexpose.ts(unexported).Evidence
After:
pnpm vitest run __tests__/components/pages/test/TestPage.page-spec.tsx: 17 passed. Covers start, letter states, extra letters, rendering on the next frame (not on input), space, error words, backspace (normal / mistyped word / freedom mode), stop on error, IME, live stats tick, finish in words and time modes, no state leaking between specs.*.spec.tsxthat uses the harness fails with "The test-page harness needs the real DOM: name the spec *.page-spec.tsx".__mt.setCustomText("かな the fox"),__mt.compose(["k","か"]),__mt.typeText("x\bな th")render かな and th as correct.Merge Danger
Door: two-way
Blast Radius: tests
The only app code touched is dev-only (
__mttyping helpers). The sharedmock-staticchange gives all test projects language JSON from disk; the whole suite still passes.🤖 Generated with Claude Code
https://claude.ai/code/session_01NZNRfGDYsGYMUTp2zYUTrv