test: library specs fail on cold cache (missing Storage polyfill in vitest setup) #238

Closed
opened 2026-06-18 02:31:49 +00:00 by spikerj · 0 comments
Owner

Problem

Four library projects fail their unit tests on a cold cache (locally, or whenever nx can't replay a cached result), while CI looked green by replaying cached pass results:

  • platform-activity-tracking — every spec crashed (TypeError: localStorage.clear is not a function)
  • shared-js-formatting-optionspersists across service re-instantiation (localStorage hydration)
  • feature-games-clue-for-sqllocalStorage.removeItem is not a function
  • feature-dev-tools-reg-ex — localStorage-backed specs

Root cause

Under the Angular @angular/build:unit-test builder's default environment, localStorage is a partial / "split" Storage: clear/removeItem throw is not a function and setItem writes aren't visible to getItem. The repo already ships a canonical in-memory Storage polyfill at testing/storage-test-setup.ts (mirroring projects/spikersoft/src/test-setup.ts), but these four library vitest.config.ts files never added it to their setupFiles.

Fix

Add the existing testing/storage-test-setup.ts to each project's setupFiles. No production code changes.

Resolved in spikersoft-angular PR #69 (merged to master).

## Problem Four library projects fail their unit tests on a **cold cache** (locally, or whenever nx can't replay a cached result), while CI looked green by replaying cached pass results: - `platform-activity-tracking` — every spec crashed (`TypeError: localStorage.clear is not a function`) - `shared-js-formatting-options` — `persists across service re-instantiation (localStorage hydration)` - `feature-games-clue-for-sql` — `localStorage.removeItem is not a function` - `feature-dev-tools-reg-ex` — localStorage-backed specs ## Root cause Under the Angular `@angular/build:unit-test` builder's default environment, `localStorage` is a partial / "split" Storage: `clear`/`removeItem` throw `is not a function` and `setItem` writes aren't visible to `getItem`. The repo already ships a canonical in-memory Storage polyfill at `testing/storage-test-setup.ts` (mirroring `projects/spikersoft/src/test-setup.ts`), but these four library `vitest.config.ts` files never added it to their `setupFiles`. ## Fix Add the existing `testing/storage-test-setup.ts` to each project's `setupFiles`. No production code changes. Resolved in spikersoft-angular PR #69 (merged to `master`).
Sign in to join this conversation.