mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-29 17:02:28 +00:00
- Fix flaky test in `tests/hashtag-preferences.test.mjs` by defining missing `fetchCalls` variable. - Fix `webtorrent` initialization error in `tests/unit/services/r2Service.storage-config.test.mjs` by ensuring `window.crypto` is available and `File` mock extends `Blob`. - Update `tests/test-helpers/setup-localstorage.mjs` to polyfill `window.crypto` using `globalThis.crypto`. - Update `scripts/run-unit-tests.mjs` to support test file filtering via command line arguments. Co-authored-by: PR0M3TH3AN <[email protected]>
76 lines
1.8 KiB
JavaScript
76 lines
1.8 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.window.crypto === "undefined" && typeof globalThis.crypto !== "undefined") {
|
|
globalThis.window.crypto = globalThis.crypto;
|
|
}
|
|
|
|
if (typeof globalThis.structuredClone === "undefined") {
|
|
globalThis.structuredClone = (val) => JSON.parse(JSON.stringify(val));
|
|
}
|
|
|
|
if (typeof globalThis.IntersectionObserver === "undefined") {
|
|
globalThis.IntersectionObserver = class IntersectionObserver {
|
|
constructor(callback) {
|
|
this.callback = callback;
|
|
}
|
|
observe(element) {}
|
|
unobserve(element) {}
|
|
disconnect() {}
|
|
};
|
|
}
|
|
|
|
if (typeof globalThis.ResizeObserver === "undefined") {
|
|
globalThis.ResizeObserver = class ResizeObserver {
|
|
constructor(callback) {
|
|
this.callback = callback;
|
|
}
|
|
observe(element) {}
|
|
unobserve(element) {}
|
|
disconnect() {}
|
|
};
|
|
}
|