Cover the app entry with tests - #8
Merged
Merged
Conversation
src/main.ts had no tests at all. It is where every bug found by hand-driving the built app actually lived, and three of those were invisible to the suite. Importing main.ts wires the entire UI, so test/app-harness.ts rebuilds the DOM from the real index.html and re-imports the module for each case. Reading the markup from disk means a control main.ts looks up by id but index.html has lost fails loudly instead of silently disabling a feature. Fakes stand in for what jsdom lacks: Worker (there is none), fetch (samples are read off disk), localStorage, <dialog> (only `open` is implemented), and Element.scrollIntoView. The worker fake replays the real parser, so the ready handshake, load tokens, superseded replies and the startup watchdog can be driven exactly. 67 cases: the loading paths (samples, picker, drag-and-drop, paste, the large-file warning, fetch and parse failures, the deep-linkable URL) and the interaction paths (search stepping and suggestions, / and Escape, pane resizing and persistence, pane tabs, the model and diagnostics dialog). Two cases carry a regression note, and both were checked by reverting the fix and confirming only that case fails: the failed load that used to strip ?sample=&node= from a model still on screen, and search stepping that hung off `change`, which a browser does not fire when the value has not been edited.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
src/main.tshad no tests. It is where every bug found by hand-driving the built app actually lived — the failed load that stripped?sample=&node=from a model still on screen, theonerrorhandler that Chrome never fires, the search stepping that hung offchange— and none of those were visible to the suite. CI now runs on every push, so it was worth giving it something to protect.The harness
Importing
main.tswires the whole UI to the currentdocument, so it cannot be called into.test/app-harness.tsrebuilds the DOM and re-imports the module for each case (vi.resetModules()+ dynamic import). The DOM is read from the realindex.html, not restated, so a controlmain.tslooks up by id but the markup has lost fails loudly instead of silently disabling a feature.Fakes for what jsdom lacks, each documented in the harness:
Workermain.tsposts and answers on demand —answer()runs the realdetectAndParse, i.e. the worker's own body — so the ready handshake, load tokens, superseded replies and the startup watchdog are all drivable.fetchpublic/.localStoragemain.tsoptional-chains it, so the persistence paths would otherwise just be skipped.<dialog>open— noshowModal,close,returnValue.submitDialog()stands in for the browser'sform[method=dialog]step, so these cases cover our handlers, not the browser semantics under them.Element.scrollIntoViewCoverage
67 cases, 180 → 247 in the suite.
Loading (
main-load.test.ts): startup empty state and the one-click sample CTA; the registry-derived dropdown; sample fetch, parse and reporting; fetch failure; the file picker; drag-and-drop including the overlay's enter/leave/child-crossing behaviour; paste, cancel and empty paste; the large-file warning both ways; parse failure keeping the previous model; superseded replies ignored; the watchdog firing for a worker that never starts and not firing for a slow parse once ready;onerrorandonmessageerror; the deep-linkable URL, including an unknown sample and an unknown node.Interaction (
main-ui.test.ts): search by id, by type, no-match, empty; Enter stepping and wrapping;changestaying idempotent; debounced suggestions;/and Escape, including that typing is never hijacked; pane resizing by keyboard and by pointer, clamping,Home, and persistence; pane tabs; the model dialog's summary, metadata, worst-first diagnostics, node xref, and the diagnostic count button.Verification
The suite passes 247/247, three consecutive runs, plus
tsc --noEmitand the build.The two cases carrying regression notes were mutation-checked: reverting each fix in
main.tsmakes exactly that case fail (and reverting the search fix fails 7 search cases). The watchdog case was checked the same way. So these aren't tests that merely pass.