Skip to content

test(frontend): bind jsdom Storage when Node Web Storage shadows it - #57

Open
mambastick wants to merge 1 commit into
mainfrom
fix/issue-56-vitest-node-webstorage
Open

mambastick wants to merge 1 commit into
mainfrom
fix/issue-56-vitest-node-webstorage

Conversation

@mambastick

Copy link
Copy Markdown
Owner

Closes #56

What and why

On Node 25+ the frontend Vitest suite failed 17 of 178 tests, mostly in app-shell.test.tsx and app-navigation.test.tsx, with TypeError: Cannot read properties of undefined (reading 'getItem'). CI pins Node 24, so this only showed up locally.

Node 25+ exposes an experimental global Web Storage API. Without --localstorage-file, its globalThis.localStorage getter returns undefined. Vitest's jsdom environment keeps that existing global instead of replacing it, so Node's broken localStorage hides jsdom's working one. A probe on Node 26 confirmed this: the global localStorage was undefined, while jsdom.window.localStorage and sessionStorage worked.

frontend/src/test/setup.ts now rebinds localStorage and sessionStorage on globalThis to the jsdom window's real Storage instances whenever they differ. On Node 24 they are already the same object, so nothing changes there. Production code, test assertions and the Vitest config are unchanged.

Checks

Runtime vitest run lint build
Node 26.8.2 (before fix) 17 failed / 161 passed — —
Node 26.8.2 178 / 178 passed pass pass
Node 26.8.2, --no-experimental-webstorage 178 / 178 passed — —
Node 26.8.2, --localstorage-file=<tmp> 178 / 178 passed — —
Node 24.22.0 (official tarball, SHA-256 verified) 178 / 178 passed pass pass (tsc -b + vite build)

Backend checks were not run because no backend files changed.

Risks / migration / rollback

  • Test harness only: no runtime, API, database or config changes, so no migration is needed. To roll back, revert the commit.
  • Node still prints its ExperimentalWarning about --localstorage-file once per worker on Node 25+. It is harmless noise.
  • No UI changes, so there is no visual evidence.

🤖 Generated with Claude Code

Node 25+ exposes an experimental global localStorage whose getter returns
undefined without --localstorage-file. Vitest keeps that global, shadowing
jsdom's Storage and failing 17 tests on Node 26. Rebind localStorage and
sessionStorage to the jsdom window in the Vitest setup file.

Closes #56

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(frontend): Vitest fails on Node 25+ because Node Web Storage shadows jsdom localStorage

1 participant