Skip to content

test: provide an in-memory localStorage for Node 26 - #425

Open
lws2004 wants to merge 1 commit into
omdsh-dev:mainfrom
lws2004:fix/test-localstorage-node26
Open

lws2004 wants to merge 1 commit into
omdsh-dev:mainfrom
lws2004:fix/test-localstorage-node26

Conversation

@lws2004

@lws2004 lws2004 commented Nov 5, 2026

Copy link
Copy Markdown

What

On Node 26 the whole suite fails at every localStorage.clear() with TypeError: Cannot read properties of undefined (reading 'clear') — 413 of 2106 tests across 31 files.

The cause is environmental, not a test bug:

  • Node 26 ships an experimental localStorage global that stays undefined unless --localstorage-file is passed.
  • Its presence shadows jsdom 25's own Storage, so window.localStorage is undefined too in the vitest jsdom environment.

package.json declares engines.node: "^22.19.0 || >=24.0.0", so Node 26 is in the supported range and pnpm test should work there.

How

Add a spec-compatible in-memory Storage in tests/setup.ts, guarded by typeof globalThis.localStorage === 'undefined' so a real Storage is never replaced. It is a Proxy over a Map, so:

  • Object.values(localStorage) sees stored entries as own enumerable properties (used by tests/dom-fence-ordinals.spec.tsx),
  • property reads/writes, has, delete, key(), length, clear, getItem, setItem, removeItem all behave like Storage.

Verification

  • Node 26.7.0 vitest run: 413 failed / 1693 passed before → 152 files / 2106 tests all passing after
  • tsc -p tsconfig.json — clean
  • No runtime code touched; only tests/setup.ts (+44 / −0)

Scope

One file: tests/setup.ts. It is inert on Node versions where jsdom provides Storage (Node 22/24 CI keeps using the native one).

On Node 26 the whole suite fails at every localStorage.clear():
TypeError: Cannot read properties of undefined (reading 'clear') —
413 of 2106 tests across 31 files.

Node 26 ships an experimental localStorage global that stays undefined
unless --localstorage-file is passed, and its presence shadows jsdom 25's
own Storage, so window.localStorage is undefined too. engines.node allows
'^22.19.0 || >=24.0.0', so Node 26 is supported and pnpm test should work.

Add a spec-compatible in-memory Storage in tests/setup.ts, guarded by
typeof globalThis.localStorage === 'undefined'. It is a Proxy over a Map so
Object.values(localStorage) sees stored entries as own enumerable
properties, matching browser/jsdom behavior.

413 failed / 1693 passed before; 152 files / 2106 tests pass after.

This branch has not been deployed

No deployments
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.

1 participant