Skip to content

fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments#1542

Open
Itzzavdheshh wants to merge 1 commit into
magic-peach:mainfrom
Itzzavdheshh:reframe-updation
Open

fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments#1542
Itzzavdheshh wants to merge 1 commit into
magic-peach:mainfrom
Itzzavdheshh:reframe-updation

Conversation

@Itzzavdheshh
Copy link
Copy Markdown

@Itzzavdheshh Itzzavdheshh commented Jun 6, 2026

Description

Fixes a critical test environment crash where the Vitest test suite failed entirely with TypeError: localStorage.clear is not a function.

Root Cause: Node.js 20+ and Bun expose a native but incomplete globalThis.localStorage that lacks standard Web Storage API methods like .clear(). This partial implementation clashes with jsdom's simulated storage, causing any test that calls localStorage.clear() to crash before assertions could run.

Fix: Updated vitest.setup.ts to detect when localStorage is missing or incomplete in the current environment. If so, a full in-memory mock is injected onto both window.localStorage and globalThis.localStorage, providing all standard methods: getItem, setItem, removeItem, clear, key, and length.

Result: All 121 tests across 13 test files now pass successfully. Previously, 7 tests were failing and the suite could not complete.


Related Issue

Closes #1539 — Vitest Tests Fail to Run due to localStorage.clear Crash


Type of Contribution

  • Bug fix
  • New feature
  • Documentation update
  • Refactor
  • GSSoC contribution

Participant Info

  • GitHub username: @Itzzavdheshh
  • Contribution level (Beginner/Intermediate/Advanced): Intermediate

Screen Recording

How to record: run bun run dev → open http://localhost:3000 → demonstrate the full working flow of your change, including any edge cases.

  • macOS: Cmd + Shift + 5 → Record Selected Portion, or use QuickTime Player
  • Windows: Win + G → Xbox Game Bar → Capture
  • Linux: OBS Studio, GNOME Screenshot tool, or kazam
  • Any OS: [Loom](https://loom.com) (free screen recorder, great for sharing)

Recording / Loom link: — this is a test infrastructure fix with no UI changes. Terminal output showing 121/121 tests passing serves as verification.

test pass
https://drive.google.com/file/d/1iGlcNf_cSLxtVc9B3LYwhuTYOkdAeu_3/view?usp=sharing



webside view
https://drive.google.com/file/d/163aJfFGPaSK2dCtXJFh4X9T95dLuaVvj/view?usp=sharing


Checklist

  • I have read the contribution guidelines
  • My changes follow the project structure
  • I have tested my changes in Chrome, Firefox, and Safari
  • bun run lint passes (no ESLint errors)
  • bunx tsc --noEmit passes (no TypeScript errors)
  • New interactive elements have aria-label / accessible names
  • No console.log statements left in
  • This PR is related to a valid issue
  • Screen recording attached above (required for UI/feature/design changes)

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 6, 2026

@itzzavdhesh is attempting to deploy a commit to the magic-peach1's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

✅ PR Format Check Passed — @Itzzavdheshh

Basic format checks passed. A maintainer will review your code changes.

This does not mean the PR is approved — it just means the format is correct.

@github-actions github-actions Bot added level:beginner Beginner level - 20 pts type:bug Bug fix type:design UI/UX design labels Jun 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

👋 Thanks for your PR, @Itzzavdheshh!

Welcome to Reframe — a browser-based video editor built for everyone 🎬

🟠 GSSoC'26 PR detected — thanks for contributing under GirlScript Summer of Code 2026!

What happens next

  1. 🤖 Automated checks — build & TypeScript typecheck will run automatically
  2. Vercel preview — a preview deployment will be created (requires maintainer authorization for fork PRs)
  3. 👀 Code review — a maintainer will review your changes
  4. 🚀 Merge — once approved, your PR will be merged!

Quick checklist

  • PR title follows Conventional Commits (e.g. feat: add dark mode)
  • Linked the issue this PR closes (e.g. Closes #123)
  • Tested the changes locally (bun run dev)
  • Build passes (bun run build)

Useful links

Happy coding! 🎉

@github-actions github-actions Bot added type:docs Documentation type:feature New feature type:refactor Code refactor type:testing Testing gssoc'26 GirlScript Summer of Code 2026 labels Jun 6, 2026
@Itzzavdheshh
Copy link
Copy Markdown
Author

Hi @magic-peach 👋

I've been looking through the open issues and picked up Issue #1539 which was causing the entire Vitest test suite to crash with TypeError: localStorage.clear is not a function in Node.js 20+ and Bun environments. The fix is minimal and isolated to vitest.setup.ts only — no production code was touched. All 121 tests across 13 test files are now passing successfully, up from 114 passing with 7 failing before.

Please let me know if you'd like me to adjust the mock implementation, add comments to the setup file for clarity, or handle any edge cases I may have missed.

Happy to address any feedback required, Thank you! 🙏

@Itzzavdheshh Itzzavdheshh changed the title **fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments** fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments Jun 6, 2026
@Itzzavdheshh Itzzavdheshh changed the title fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc'26 GirlScript Summer of Code 2026 level:beginner Beginner level - 20 pts type:bug Bug fix type:design UI/UX design type:docs Documentation type:feature New feature type:refactor Code refactor type:testing Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Vitest Test Suite Crashes with TypeError: localStorage.clear is not a function in Node.js 20+ / Bun.

2 participants