Run unit tests in a jsdom environment via Vitest#150
Open
CarsonDavis wants to merge 3 commits into
Open
Conversation
The browser-coupled unit specs (map-engine adapters, engine registry, panel manager) read window/document at import time, so they errored under plain Node and aborted the whole Playwright unit run — the suite gave zero protection. Run the unit suite under Vitest with a jsdom environment instead; Playwright keeps the e2e suite. - Add vitest + jsdom; vitest.config.ts (jsdom env, alias for generated pre/tools), tests/unit/vitest.setup.js (import-time window.L stub), tests/unit/__mocks__/preTools.js - Swap tests/unit import specifier @playwright/test -> vitest (38 files) - Mock mmgisAPI in the panelManager specs to cut the heavy Map_ import chain - Scope Playwright to tests/e2e; point npm test/test:unit at Vitest - CI: Node 18 -> 20; run the hermetic unit step via Vitest before e2e setup 9 pre-existing stale tests are revealed by finally running the suite; they are tracked and fixed in #149. Refs #148, #149.
✅ Version Already UpdatedThis PR includes a manual version update to No automatic version bump needed. |
Replaces the repeated inline vi.mock factory in the 5 panelManager specs with Vitest's adjacent __mocks__ automock, so each spec is a single vi.mock() line. No behavior change (660 pass / 9 pre-existing fail).
CarsonDavis
commented
Jun 16, 2026
| "build:themes": "bash scripts/build-themes.sh", | ||
| "test": "playwright test", | ||
| "test:unit": "cross-env PLAYWRIGHT_TEST_UNIT_ONLY=true playwright test tests/unit", | ||
| "test": "vitest run", |
Author
There was a problem hiding this comment.
are we changing the behavior here? i think we should be running playwright and vitest
Preserves the prior 'npm test runs everything' behavior and matches the AGENTS.md description; test:unit runs just the fast unit suite.
This was referenced Jun 17, 2026
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.
What this does
Makes the unit test suite actually run. Right now it doesn't — and it never has in CI — so a large set of written unit tests (~200 cases) provides zero protection. This migrates the unit suite to Vitest with a jsdom (simulated-browser) environment so those tests can finally execute. Playwright keeps the end-to-end suite.
Implements #148.
Why the tests weren't running
Many unit specs test browser-coupled code — the map-engine adapters, the engine registry, the panel manager. That code reaches for browser globals like
windowthe moment it loads. Unit tests run in plain Node, which has no browser, so these specs crashed at import — before a single assertion — which aborted the entire unit run.This stayed invisible for a long time:
The fix is to give the unit tests a simulated DOM (jsdom), which Vitest provides out of the box.
Changes
vitest+jsdom. Newvitest.config.ts(jsdom environment, an alias for the build-generatedsrc/pre/tools.js, a setup file),tests/unit/vitest.setup.js(an import-timewindow.Lstub), and a sharedmmgisAPItest stub.tests/unit/**/*.spec.jsfrom@playwright/testtovitest(one line per file — thetest/expectAPI is the same).mmgisAPIin the panel-manager specs so they don't drag in the entire map-rendering stack just to test panel logic.tests/e2e.npm teststill runs the full suite (Vitest unit, then Playwright e2e);npm run test:unitruns just the fast unit half (test:unit:watchfor the dev loop).Result
660 passed / 9 failed / 669 total— previously the suite couldn't get past import. All 38 spec files now execute, including the ~200 previously-dead browser-dependent cases.windowevent instead of the current in-app event bus, and 1 validator test expects an error the validator never emits. They're fixed in Fix the stale unit tests revealed by the jsdom test-environment migration #149 (stacked on this branch).package-lock.json(the new dev-dependency tree); the hand-written code change is small.