You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
apps/web unit tests fail on Node 26: Node's built-in localStorage replaces jsdom's #2006
On Node 26 the dashboard's unit tests fail locally. A builder on Node v26.3.1 saw 96 failures in 11 files of the apps/web vitest suite (Terminal.*, VirtualKeyboard, architect-toolbar, WorkView.dashboard-host). CI is unaffected because its workflows pin Node 22, so the failure is invisible there and every developer on a newer Node sees a red suite that has nothing to do with their change.
Reproduced on main at ab0fa50a9, Node v26.3.1:
cd apps/web
npx vitest run __tests__/VirtualKeyboard.test.tsx
# Tests 14 failed (14)
# TypeError: Cannot read properties of undefined (reading 'getItem')
# apps/web/src/lib/api.ts:44 return localStorage.getItem('codev-tower-key');
NODE_OPTIONS=--no-experimental-webstorage npx vitest run __tests__/VirtualKeyboard.test.tsx
# Tests 14 passed (14)
Root cause
Newer Node has a built-in localStorage global (experimental Web Storage). In the test process it takes the place of the one jsdom provides, and its value is undefined here, so localStorage.getItem throws. With the Node feature switched off, jsdom's localStorage is used again and the suite passes (the builder reports 482 of 482 for the whole suite with the flag).
Fix
Make the apps/web test setup independent of the Node version: in the vitest setup file for apps/web, make globalThis.localStorage (and sessionStorage) the jsdom window's storage before any test module loads. Do not put --no-experimental-webstorage in a script or in NODE_OPTIONS: Node 22, which package.json still supports and CI runs, does not know that flag. Do not change apps/web/src/lib/api.ts; the application code is right for a browser.
Testing
The apps/web vitest suite passes on Node 22 (CI) and on Node 26 with no flag set.
Check the other vitest projects that use jsdom for the same failure on Node 26, and apply the same setup where it occurs.
Activity