fix: the suite finds a localStorage again
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.
This commit is contained in:
1 parent
64cc010f01
commit
b98cc550c3
2 files changed
+16
No files matched your search
@@ -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<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 });
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user