diff --git a/tests/setup.ts b/tests/setup.ts new file mode 100644 index 0000000..51d385c --- /dev/null +++ b/tests/setup.ts @@ -0,0 +1,15 @@ +// 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(); + 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 }); +} diff --git a/vite.config.ts b/vite.config.ts index 584d000..8dc70c7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -19,6 +19,7 @@ export default defineConfig({ // jsdom supplies a global DOMParser, so the export/import specs need no setup. test: { environment: 'jsdom', + setupFiles: ['tests/setup.ts'], include: ['tests/**/*.test.ts'], globals: false, // A build+re-import leg runs ~10s when the whole suite competes for the CPU,