-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
36 lines (29 loc) · 870 Bytes
/
Copy pathvitest.setup.ts
File metadata and controls
36 lines (29 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Node 24+ exposes a native `localStorage` global that shadows jsdom's and
// throws unless `--localstorage-file` is passed. Override it with a simple
// in-memory Storage so tests work on Node 24/26 and CI alike.
class MemoryStorage implements Storage {
#store = new Map<string, string>();
get length(): number {
return this.#store.size;
}
clear(): void {
this.#store.clear();
}
getItem(key: string): string | null {
return this.#store.get(key) ?? null;
}
key(index: number): string | null {
return [...this.#store.keys()][index] ?? null;
}
removeItem(key: string): void {
this.#store.delete(key);
}
setItem(key: string, value: string): void {
this.#store.set(key, String(value));
}
}
Object.defineProperty(globalThis, "localStorage", {
value: new MemoryStorage(),
configurable: true,
writable: true,
});