Node 26 defines its own `localStorage` global — undefined unless the process is given --localstorage-file — and it shadows the one jsdom installs. Every module that reads storage at import time threw before a test could run, so 37 of 65 files failed to collect. A setup file defines the property when it is missing.
16 lines
684 B
TypeScript
16 lines
684 B
TypeScript
// Node 26 ships its own `localStorage` global, undefined unless the process gets
|
|
// --localstorage-file, and it shadows the one jsdom installs. Modules that read
|
|
// storage at import time then throw before a single test runs.
|
|
if (!globalThis.localStorage) {
|
|
const store = new Map<string, string>();
|
|
const shim: Storage = {
|
|
get length() { return store.size; },
|
|
key: (i) => [...store.keys()][i] ?? null,
|
|
getItem: (k) => store.get(k) ?? null,
|
|
setItem: (k, v) => void store.set(k, String(v)),
|
|
removeItem: (k) => void store.delete(k),
|
|
clear: () => store.clear(),
|
|
};
|
|
Object.defineProperty(globalThis, 'localStorage', { value: shim, configurable: true });
|
|
}
|