forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

test-setup.ts27 lines, 1.3 KiBHistoryRawDownload
1// Node exposes an experimental global localStorage that is undefined unless a
2// --localstorage-file is provided, and this jsdom version does not expose one
3// for the configured test origin. Keep the test storage local to each worker.
4if (typeof window !== "undefined") {
5 // jsdom intentionally does not implement scrolling and logs a warning when
6 // UI code calls it. Scrolling is outside the scope of these component tests.
7 window.scrollTo = () => undefined;
8 const values = new Map<string, string>();
9 const storage = {
10 get length() { return values.size; },
11 clear() { values.clear(); },
12 getItem(key: string) { return values.get(String(key)) ?? null; },
13 key(index: number) { return Array.from(values.keys())[index] ?? null; },
14 removeItem(key: string) { values.delete(String(key)); },
15 setItem(key: string, value: string) { values.set(String(key), String(value)); },
16 };
17 Object.defineProperty(window, "localStorage", { configurable: true, value: storage });
18 Object.defineProperty(window, "sessionStorage", { configurable: true, value: storage });
19 Object.defineProperty(globalThis, "localStorage", {
20 configurable: true,
21 value: storage,
22 });
23 Object.defineProperty(globalThis, "sessionStorage", {
24 configurable: true,
25 value: window.sessionStorage,
26 });
27}