mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-18 09:06:06 +00:00
Merge pull request #1403 from nick4810:fix/node25+-test-compatibility
Node25+ Test Compatibility
This commit is contained in:
commit
9bd05580e7
1 changed files with 37 additions and 0 deletions
|
|
@ -32,6 +32,43 @@ if (typeof window !== 'undefined' && !window.ResizeObserver) {
|
|||
window.ResizeObserver = ResizeObserver;
|
||||
}
|
||||
|
||||
// Node 25+ exposes a broken native localStorage stub on globalThis (missing
|
||||
// Storage methods) that shadows jsdom's implementation.
|
||||
if (typeof window !== 'undefined') {
|
||||
const brokenTargets = [globalThis, window].filter(
|
||||
(target) => typeof target?.localStorage?.getItem !== 'function'
|
||||
);
|
||||
|
||||
if (brokenTargets.length > 0) {
|
||||
let store = {};
|
||||
const storage = {
|
||||
getItem: (key) => store[key] ?? null,
|
||||
setItem: (key, value) => {
|
||||
store[key] = String(value);
|
||||
},
|
||||
removeItem: (key) => {
|
||||
delete store[key];
|
||||
},
|
||||
clear: () => {
|
||||
store = {};
|
||||
},
|
||||
get length() {
|
||||
return Object.keys(store).length;
|
||||
},
|
||||
key: (i) => Object.keys(store)[i] ?? null,
|
||||
};
|
||||
|
||||
for (const target of brokenTargets) {
|
||||
Object.defineProperty(target, 'localStorage', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: storage,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
if (!window.requestAnimationFrame) {
|
||||
window.requestAnimationFrame = (cb) => setTimeout(cb, 16);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue