test: shield the web suite from Node's built-in web storage - #416
Merged
Conversation
Node 25 enabled the Web Storage API by default (nodejs/node#57666): the vitest worker's globals then carry Node's localStorage/sessionStorage, which shadow happy-dom's and, with no --localstorage-file backing, throw on every access (vitest-dev/vitest#8757). happy-dom's window.localStorage delegates to the same broken storage. The state is reachable on Node 22/24 via NODE_OPTIONS=--experimental-webstorage, and shells that skip the repo's mise pin (login non-interactive shells resolve Homebrew's node 26) hit it today — a review environment failed 48 otherwise-green tests this way. A vitest setup file probes each storage global with a real write and, only when it is broken or missing, replaces it with an in-memory implementation — a healthy environment is left untouched. Verified both ways: 642 tests pass plain and under the --experimental-webstorage simulation, which failed 16/16 in prefs.test.ts before the shim.
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.
Node 25 enabled the Web Storage API by default (nodejs/node#57666): the vitest worker's globals
then carry Node's
localStorage/sessionStorage, which shadow happy-dom's and — with no--localstorage-filebacking — throw on every access (vitest-dev/vitest#8757). happy-dom'swindow.localStoragedelegates to the same broken storage, so re-binding to the window doesn'thelp. The state is reachable on Node 22/24 via
NODE_OPTIONS=--experimental-webstorage, and anyshell that skips the repo's mise pin resolves a newer node and hits it for real — a login
non-interactive shell (the shape review sandboxes use) resolves Homebrew's node 26 on a typical
setup, which is exactly how the PR #415 review environment failed 48 otherwise-green tests.
The fix is a vitest setup file that probes each storage global with a real write and, only when it
is broken or missing, installs an in-memory implementation. A healthy environment is left
completely untouched.
Verification:
NODE_OPTIONS=--experimental-webstorage: 16/16 prefs tests fail (the reported class)npm run check(mise node 22.23.1): 642/642just check: 2172 passed