Repository navigation
Description
Bug Description
Running the test suite fails immediately with TypeError: localStorage.clear is not a function. This happens because Node.js 20+ and Bun expose a native but incomplete globalThis.localStorage that lacks standard methods like .clear(). When jsdom also tries to set up its own simulated storage, the two implementations clash — and whichever partial native one wins causes test files that call localStorage.clear() to crash before any assertions even run.
Steps to Reproduce
- Clone the repository and install dependencies
- Ensure you are running Node.js 20+ or Bun as the JS runtime
- Run the test suite via
bun run testornpx vitest - Observe the crash — no tests execute
Expected Behavior
The test suite should run successfully. localStorage in the jsdom environment should be a fully functional mock with all standard Web Storage API methods (getItem, setItem, removeItem, clear, key, length) available.
Actual Behavior
The test runner crashes immediately with:
TypeError: localStorage.clear is not a function
This error surfaces in at least two test files:
src/components/__tests__/ThemeToggle.test.tsx(line 11)src/lib/tests/editorPersistence.test.ts(line 17)
The root cause is in vitest.setup.ts, which does not guard against or replace the partial native localStorage that Node.js 20+ / Bun inject into globalThis before jsdom initializes.
Expected Behavior
The vitest.setup.ts file should detect when localStorage is missing .clear() (or is otherwise incomplete) and replace it with a full in-memory mock, e.g.:
if (typeof window !== 'undefined') {
if (!window.localStorage || typeof window.localStorage.clear !== 'function') {
let store: Record<string, string> = {};
const mockLocalStorage = {
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => { store[key] = String(value); },
removeItem: (key: string) => { delete store[key]; },
clear: () => { store = {}; },
length: 0,
key: (index: number) => Object.keys(store)[index] || null,
};
Object.defineProperty(window, 'localStorage', { value: mockLocalStorage, writable: true });
Object.defineProperty(globalThis, 'localStorage', { value: mockLocalStorage, writable: true });
}
}Browser and OS Info
- OS: Windows 11
- Browser: N/A (server-side / test runner environment)
- Runtime: Node.js 20+ or Bun
- Vitest version: (please fill in)
Video Format (if relevant)
N/A
Screenshots / Screen Recording
TypeError: localStorage.clear is not a function
at vitest.setup.ts (or ThemeToggle.test.tsx:11 / editorPersistence.test.ts:17)
Activity
github-actions commentedon Jun 6, 2026
👋 Thanks for opening an issue, @Itzzavdheshh!
Our maintainers will review this shortly 🚀
Before you start working
For GSSoC'26 contributors
If you're contributing under GirlScript Summer of Code 2026, please mention it in your comment when requesting assignment:
Architecture notes
Reframe is a static Next.js app with
output: "export". Key points:headers()innext.config.tswon't work — usevercel.jsoninsteadnot-found.tsxrequirespublic/404.html+vercel.jsonroutes configHappy contributing! ⭐ Star the repo if you find it useful!
[-][Bug] **Vitest Test Suite Crashes with `TypeError: localStorage.clear is not a function` in Node.js 20+ / Bun**[/-][+][Bug] Vitest Test Suite Crashes with `TypeError: localStorage.clear is not a function` in Node.js 20+ / Bun[/+][-][Bug] Vitest Test Suite Crashes with `TypeError: localStorage.clear is not a function` in Node.js 20+ / Bun[/-][+][Bug] Vitest Test Suite Crashes with `TypeError: localStorage.clear is not a function` in Node.js 20+ / Bun.[/+]Itzzavdheshh commentedon Jun 6, 2026
/assign
github-actions commentedon Jun 6, 2026
Hey @Itzzavdheshh, this issue has been assigned to you! 🎉 Please make progress within 5 days or it will be automatically unassigned due to inactivity.
Itzzavdheshh commentedon Jun 6, 2026
Hi @magic-peach Thanku for letting me work on this issue .
github-actions commentedon Jun 8, 2026
Hey @Itzzavdheshh, just a friendly reminder that this issue has had no activity for 2 days. Please leave an update or let us know if you need help! ⏰
github-actions commentedon Jun 12, 2026
Hey @Itzzavdheshh, final warning!⚠️ This issue has had no activity for 4 days and will be automatically unassigned in 24 hours if there is no update.
Itzzavdheshh commentedon Jun 12, 2026
Hey @magic-peach i already raise a PR so i request you to please check the PR
Itzzavdheshh commentedon Jun 15, 2026
Hey @magic-peach you there ?
github-actions commentedon Jun 21, 2026
This issue has been unassigned from @Itzzavdheshh due to 5 days of inactivity and is open for anyone to pick up — comment
/assignto claim it!vipul674 commentedon Jun 21, 2026
I would like to work on this under GSSoC'26. Please assign it to me.