test(web): JS unit-test layer for static modules (closes #641)#760
Merged
test(web): JS unit-test layer for static modules (closes #641)#760
Conversation
Stand up a vitest + jsdom suite under packages/memtomem/tests-js/ for the hand-rolled static modules in src/memtomem/web/static/. Until now the only automated guards on those modules were locale-parity and the i18n AST-grep — every behavioural change relied on manual sessions or ad-hoc Playwright runs, and #587 / #595 / #639 each shipped a UI bug whose minimal repro was a 10-line jsdom assertion. The runner loads the production index.html into JSDOM, strips its <script> tags, and injects requested static modules verbatim — no build step, matching how FastAPI serves them. ``bootApp`` shims ``matchMedia`` (used by ``initTheme`` at top level) and stubs the locale fetch from disk so ``I18N`` boots with real translation maps. Three regression guards: - ``_renderMemorySourceTree`` orphan rendering (#639): asserts ``.source-vendor-orphan`` block + user sub-tab badge counts orphans. - empty user vendor with orphan-only sources (#639 review): asserts the empty-state placeholder is suppressed when orphans are real content. - ``I18N.applyDOM`` ``data-i18n-placeholder`` refresh (#595): asserts placeholder attributes update on language change without static-key clobber. CI: new ``test-js`` job runs ``npm ci && npm test`` on Node 20. Failure fails the same build as pytest. Co-Authored-By: Claude <[email protected]>
This was referenced May 4, 2026
- Fix matchMedia comment: app.js queries 'prefers-color-scheme: light', not 'dark' (shim returns matches:false either way, comment-only). - Add note next to the DCL-handler stub list so future contributors extend it when adding a new top-level call in app.js's DOMContentLoaded handler. - Drop the unused `let dom` in render-memory-source-tree.test.mjs (only window/document are read inside the tests). Co-Authored-By: Claude <[email protected]>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
packages/memtomem/tests-js/(vitest + jsdom) loads the productionindex.htmlinto JSDOM, strips its<script>tags, and injects the static modules verbatim — no build step, matching how FastAPI serves them. The harness shimsmatchMedia(used byinitThemeat top level) and serves/locales/*.jsonfrom disk soI18Nboots with real translation maps._renderMemorySourceTreeorphan rendering (fix(web): render orphan-indexed sources in Sources tab #639): asserts the.source-vendor-orphanblock surfaces under User vendor and the sub-tab badge counts orphans.I18N.applyDOMdata-i18n-placeholderrefresh (feat(web): namespace cluster — preview echo + honest placeholder + helper text (#581) #595): asserts placeholder attributes update on language change without the static-key clobber.test-jsCI job runsnpm ci && npm teston Node 20; failure fails the same build as pytest.Closes #641.
Test plan
npm testpasses locally (5 tests in 2 files, ~470ms).DOMContentLoadedhandler —_initTabHelp,_indexingHydrateFromServer, etc. — are stubbed pre-DCL).test-jsjob runs green on this PR.Notes for reviewers
JSDOMper test (Node env) instead of vitest's shared jsdom env, because app.js carries top-level event-listener registrations and a per-file shared globalThis would leak handler state across tests.STATEandI18Nare top-levelconstin their modules, so they don't auto-populatewindow. The bootstrap shim inbootApplifts them ontowindowso tests can mutate them. Function declarations (_renderMemorySourceTreeetc.) populatewindowautomatically per script semantics — no shim needed for those.🤖 Generated with Claude Code