Files
bitvid/tests/test-helpers/setup-localstorage.mjs
T
google-labs-jules[bot] b285819145 fix(storage): resolve db connection leaks and patch test environment
- Added `db.close()` to exported functions in `js/storage/dmDb.js` to ensure IndexedDB connections are released.
- Patched `tests/test-helpers/setup-localstorage.mjs` to include a `structuredClone` polyfill required by `fake-indexeddb` in Node.js environments.
- Updated `tests/dm-normalization.test.mjs`, `tests/dm-db.test.mjs`, and `tests/nostr/dm-direct-message-flow.test.mjs` to conditionally initialize `fake-indexeddb` to prevent global conflicts.
- Verified fixes by running unit tests and the `scripts/agent/interop-test.mjs` E2E suite.
2026-01-19 16:24:07 +00:00

50 lines
1.2 KiB
JavaScript

if (typeof globalThis.window === "undefined") {
globalThis.window = {};
}
if (typeof globalThis.self === "undefined") {
globalThis.self = globalThis;
}
if (typeof globalThis.WebSocket === "undefined") {
globalThis.WebSocket = class WebSocket {};
}
if (typeof globalThis.navigator === "undefined") {
globalThis.navigator = { userAgent: "node" };
}
if (typeof globalThis.window.WebSocket === "undefined") {
globalThis.window.WebSocket = globalThis.WebSocket;
}
if (typeof globalThis.window.navigator === "undefined") {
globalThis.window.navigator = globalThis.navigator;
}
if (typeof globalThis.localStorage === "undefined") {
const store = new Map();
globalThis.localStorage = {
getItem(key) {
return store.has(key) ? store.get(key) : null;
},
setItem(key, value) {
store.set(String(key), String(value));
},
removeItem(key) {
store.delete(key);
},
clear() {
store.clear();
},
};
}
if (typeof globalThis.window.localStorage === "undefined") {
globalThis.window.localStorage = globalThis.localStorage;
}
if (typeof globalThis.structuredClone === "undefined") {
globalThis.structuredClone = (val) => JSON.parse(JSON.stringify(val));
}