Skip to content

fix(tests): install a working Web Storage in the test setup - #2455

Closed
dcccrypto wants to merge 1 commit into
playgroundfrom
fix/chart-drawings-tests
Closed

fix(tests): install a working Web Storage in the test setup#2455
dcccrypto wants to merge 1 commit into
playgroundfrom
fix/chart-drawings-tests

Conversation

@dcccrypto

Copy link
Copy Markdown
Owner

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 / useChartDrawingTool died in beforeEach on:

TypeError: window.localStorage.clear is not a function

So I probed what window.localStorage actually is in this environment:

ctor:      undefined
protoKeys: [constructor, __defineGetter__, hasOwnProperty, ...]   ← Object.prototype
methods:   getItem=undefined setItem=undefined removeItem=undefined
           clear=undefined key=undefined

It isn't a partial Storage. It's {}. Nothing is implemented.

Only 3 of ~259 test files worked around this with their own vi.stubGlobal mock. 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.ts 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 rather than shadowing it
  • Per-file vi.stubGlobal('localStorage', ...) still overrides it — the 3 existing workarounds keep working untouched
  • Both cleared in afterEach. 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 the lib/slabCache leak in fix(tests): retarget 20 tests left behind by the wallet bundle-split refactor #2451

Plus __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

before after
failing tests 95 66
failing files 28 26
  • The remaining failing set is a strict subset of the baseline — no test regressed. A global environment change deserves that check, so I ran the full suite rather than just the cluster.
  • npx tsc --noEmit clean
  • Mutation-verified: disabling the polyfill fails both the guard and the chart tests

One file of production-adjacent change (setup.ts), one new guard file. No product code touched.

cd app && npx vitest run __tests__/setup-storage.test.ts \
  __tests__/hooks/useChartDrawings.test.ts \
  __tests__/hooks/useChartDrawingTool.test.ts

Stacks cleanly with #2451#2454 — disjoint files, all based on playground.

🤖 Generated with Claude Code

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>
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
percolator-launch Ready Ready Preview, Comment Jul 21, 2026 7:00pm
percolator-mainnet Ready Ready Preview, Comment Jul 21, 2026 7:00pm
percolator-playground Ready Ready Preview, Comment Jul 21, 2026 7:00pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e0a6a32-a574-4952-a0cb-ab7f2230f307

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/chart-drawings-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dcccrypto

Copy link
Copy Markdown
Owner Author

Closing as superseded — this landed upstream independently.

The test-maintenance batch merged into playground (now 8bab3ced) fixed the missing Web Storage in the test setup in 7817632 (test: restore Web Storage + drop tests for routes this branch deleted).

Verified on the current base rather than assumed:

  • I ran the full suite on 8bab3ced alone. It is down to 14 failures / 4 files, and none of them are in this PR's target files — they pass on the base as-is.
  • Re-checked specifically for this PR's scope: nothing left for it to fix.
  • This branch now conflicts with playground for the same reason: upstream edited the very files it touches.

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.

@dcccrypto dcccrypto closed this Jul 28, 2026
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