fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments#1542
fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments#1542Itzzavdheshh wants to merge 1 commit into
Conversation
….js 20+ / Bun environments**
|
@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. |
✅ PR Format Check Passed — @ItzzavdheshhBasic 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. |
👋 Thanks for your PR, @Itzzavdheshh!Welcome to Reframe — a browser-based video editor built for everyone 🎬
What happens next
Quick checklist
Useful links
Happy coding! 🎉 |
|
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 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! 🙏 |
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
fix: resolve localStorage.clear crash in Vitest test suite for Node.js 20+ / Bun environments
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.localStoragethat lacks standard Web Storage API methods like.clear(). This partial implementation clashes with jsdom's simulated storage, causing any test that callslocalStorage.clear()to crash before assertions could run.Fix: Updated
vitest.setup.tsto detect whenlocalStorageis missing or incomplete in the current environment. If so, a full in-memory mock is injected onto bothwindow.localStorageandglobalThis.localStorage, providing all standard methods:getItem,setItem,removeItem,clear,key, andlength.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.clearCrashType of Contribution
Participant Info
Screen Recording
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
bun run lintpasses (no ESLint errors)bunx tsc --noEmitpasses (no TypeScript errors)aria-label/ accessible namesconsole.logstatements left in