Skip to content

fix(test): restore green Jest frontend suite (jsdom pin + snek coverage)#382

Merged
JesperDramsch merged 1 commit into
mainfrom
fix/jest-jsdom-location
Jun 27, 2026
Merged

fix(test): restore green Jest frontend suite (jsdom pin + snek coverage)#382
JesperDramsch merged 1 commit into
mainfrom
fix/jest-jsdom-location

Conversation

@JesperDramsch

Copy link
Copy Markdown
Owner

Problem

Run JavaScript Tests has been red on main since ~2026-03-17 and blocks unrelated PRs (it forced admin-merges of #375/#372). Two independent regressions:

1. jsdom 26 broke the location mocks (11 failing tests)

jest-environment-jsdom was bumped to ^30.3.0 (which pulls jsdom 26) while jest core stayed at 29. jsdom 26 makes window.location non-configurable, so the delete window.location / Object.defineProperty(window, 'location') mocks used across the suite throw:

  • TypeError: Cannot redefine property: location (favorites.test.js)
  • Not implemented: navigationgetQueryVariable/filter tests read the real jsdom location instead of the mock

Fix: pin jest-environment-jsdom back to ^29.7.0 to match jest core (restores jsdom 20 semantics) and regenerate the lockfile. Verified locally: full suite green on jsdom 20.

2. snek.js dropped below coverage threshold

#340 added the newsletter speech bubble to snek.js without tests, dropping function coverage to 28.57% (threshold 40%) — an independent gate failure even with jsdom fixed.

Fix (not a threshold relaxation): added a Newsletter Speech Bubble test block covering dismissSpeechBubble, the close-button and newsletter-link dismiss handlers, and the dismissed / not-dismissed branches. snek.js now exceeds all thresholds: stmts/lines 90.32%, branches 100%, funcs 71.42%.

Result

node node_modules/jest/bin/jest.js --coverage --ci --maxWorkers=2
Test Suites: 15 passed, 15 total
Tests:       423 passed, 423 total   (was 419; +4 new)
exit 0

Follow-up (separate PR)

Modernise the location mocks to window.history.replaceState so the suite can move forward to jest + jsdom v30 instead of pinning to 29.

Two independent regressions kept "Run JavaScript Tests" red on main and
blocked unrelated dependabot PRs:

1. jest-environment-jsdom was bumped to ^30.3.0 (jsdom 26) while jest core
   stayed at 29. jsdom 26 makes window.location non-configurable, so the
   `delete window.location` / Object.defineProperty mocks used across the
   frontend tests throw ("Cannot redefine property: location" /
   "navigation not implemented"), failing 11 tests. Pin
   jest-environment-jsdom back to ^29.7.0 to match jest core and restore
   jsdom 20 location semantics. Verified: full suite green on jsdom 20.

2. snek.js coverage fell below threshold after #340 added the newsletter
   speech bubble without tests (functions 28.57% vs 40% required). Add a
   "Newsletter Speech Bubble" test block covering dismissSpeechBubble, both
   dismiss handlers, and the dismissed/not-dismissed branches. snek.js now
   exceeds all thresholds (stmts/lines 90%, branches 100%, funcs 71%) with
   no threshold relaxation.

Full suite: 15 suites, 423 tests passing with --coverage --ci.

Follow-up (separate PR): modernise the location mocks (history.replaceState)
so the suite can move to jest + jsdom v30.
@github-actions

Copy link
Copy Markdown

📊 Frontend Test Coverage Report

⚠️ Coverage report not found

@JesperDramsch JesperDramsch merged commit 08dcdea into main Jun 27, 2026
14 checks passed
@JesperDramsch JesperDramsch deleted the fix/jest-jsdom-location branch June 27, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant