fix(tests): install a working Web Storage in the test setup - #2455
fix(tests): install a working Web Storage in the test setup#2455dcccrypto wants to merge 1 commit into
Conversation
Fourth slice of the 65 CI failures #2450 exposed. Fixes 29 in one change. `window.localStorage` in this environment is a bare object with NO Storage methods on it — `getItem`, `setItem`, `removeItem`, `clear` and `key` are all `undefined`, the constructor is undefined and the prototype is Object.prototype. It is not a partial implementation; it is `{}`. The whole useChartDrawings/useChartDrawingTool cluster (29 tests, 2 files) died on `window.localStorage.clear is not a function` in beforeEach, before asserting anything. The failure reads as a chart bug and is nothing of the sort. Only 3 of ~259 test files worked around this with their own vi.stubGlobal mock. Every other test touching persistence has been running against a dead Storage — so that code path was never actually exercised. setup.ts now installs an in-memory Storage for localStorage and sessionStorage, guarded on `getItem` being absent so it defers to a real implementation if the environment ever gains one. Per-file `vi.stubGlobal('localStorage', ...)` still overrides it. Both are cleared in afterEach: Storage outlives a test, and leftover keys let one test's persisted state satisfy the next one's assertions. Adds __tests__/setup-storage.test.ts so a regression here surfaces as one clear failure instead of 29 confusing ones spread across unrelated files. Mutation-verified: disabling the polyfill fails both the guard and the chart tests. Measured on the full suite: 95 -> 66 failures, 28 -> 26 files. The remaining failing set is a strict SUBSET of the baseline — no test regressed. tsc --noEmit clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing as superseded — this landed upstream independently. The test-maintenance batch merged into Verified on the current base rather than assumed:
Rebasing it would produce a no-op at best, so closing rather than leaving a stale PR in the queue. For what it's worth the remaining 14 failures are covered by the three PRs I'm keeping open: #2451 (useWallet + ConnectButton, 7), #2459 (Header nav, 4), #2458 (Portfolio PORT-007, 1). With those three stacked the suite is 2823 passed, 0 failed. |
Fourth slice of the 65 failures #2450 exposed. Fixes 29 in a single change, and repairs the test environment for everything written after it.
The chart-drawings cluster was never a chart problem
All 29 tests in
useChartDrawings/useChartDrawingTooldied inbeforeEachon:So I probed what
window.localStorageactually is in this environment:It isn't a partial Storage. It's
{}. Nothing is implemented.Only 3 of ~259 test files worked around this with their own
vi.stubGlobalmock. Every other test that touches persistence has been running against a dead Storage — meaning that code path was never actually exercised, whether the test was green or red.Patching two more files with duplicate stubs would have hidden that. Fixing the environment is the actual fix.
The change
__tests__/setup.tsinstalls an in-memoryStorageforlocalStorageandsessionStorage:getItembeing absent, so it defers to a real implementation if the environment ever gains one rather than shadowing itvi.stubGlobal('localStorage', ...)still overrides it — the 3 existing workarounds keep working untouchedafterEach. Storage outlives a test; leftover keys let one test's persisted state quietly satisfy the next one's assertions — the same vacuous-pass failure mode as thelib/slabCacheleak in fix(tests): retarget 20 tests left behind by the wallet bundle-split refactor #2451Plus
__tests__/setup-storage.test.ts, so a regression here shows up as one clear failure instead of 29 confusing ones scattered across files that look unrelated to storage.Evidence
npx tsc --noEmitcleanOne file of production-adjacent change (
setup.ts), one new guard file. No product code touched.Stacks cleanly with #2451–#2454 — disjoint files, all based on
playground.🤖 Generated with Claude Code