Fix checkpoint regressions: jsdom localStorage shim (Node 22 shadowing) + restore persistent nav links required by §7 one-tap emergency reachability
This commit is contained in:
parent
e83946c207
commit
3cd9a2377a
3 changed files with 48 additions and 1 deletions
35
tests/setup.ts
Normal file
35
tests/setup.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Vitest setup — runs before every test file.
|
||||
*
|
||||
* Why: on Node >=22.4 the experimental native `localStorage` global shadows
|
||||
* jsdom's implementation and is `undefined` unless `--localstorage-file` is
|
||||
* passed, so jsdom-environment tests see `localStorage === undefined`
|
||||
* (ExperimentalWarning at runtime). Install a minimal in-memory stand-in
|
||||
* whenever the global is missing.
|
||||
*/
|
||||
class MemoryStorage implements Storage {
|
||||
private map = new Map<string, string>();
|
||||
get length(): number {
|
||||
return this.map.size;
|
||||
}
|
||||
clear(): void {
|
||||
this.map.clear();
|
||||
}
|
||||
getItem(key: string): string | null {
|
||||
return this.map.has(key) ? (this.map.get(key) as string) : null;
|
||||
}
|
||||
key(index: number): string | null {
|
||||
return [...this.map.keys()][index] ?? null;
|
||||
}
|
||||
removeItem(key: string): void {
|
||||
this.map.delete(key);
|
||||
}
|
||||
setItem(key: string, value: string): void {
|
||||
this.map.set(key, String(value));
|
||||
}
|
||||
}
|
||||
|
||||
const g = globalThis as unknown as { localStorage?: Storage };
|
||||
if (typeof g.localStorage === "undefined") {
|
||||
g.localStorage = new MemoryStorage();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue