Skip to content

apps/web unit tests fail on Node 26: Node's built-in localStorage replaces jsdom's #2006

Backlog

Description

@waleedkadous

Problem

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

  1. added
    area/dashboard
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/dashboard

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions