mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
fix(test): polyfill synchronous requestIdleCallback for unit tests
Fixes flaky/failing unit tests in `tests/state/profile-cache.test.mjs` caused by the recent optimization to defer `localStorage` writes using `requestIdleCallback`. In the JSDOM environment, `requestIdleCallback` was missing, causing a fallback to `setTimeout`, which introduced asynchronous behavior that the existing tests did not account for. This change adds a synchronous polyfill for `requestIdleCallback` in `tests/test-helpers/setup-localstorage.mjs`, ensuring that deferred writes happen immediately during testing, restoring deterministic behavior. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
88cca17de0
commit
614e30a61a
1 file changed
+10
@@ -44,6 +44,16 @@ if (typeof globalThis.window.localStorage === "undefined") {
|
||||
globalThis.window.localStorage = globalThis.localStorage;
|
||||
}
|
||||
|
||||
// Polyfill requestIdleCallback for synchronous testing if undefined
|
||||
if (typeof globalThis.requestIdleCallback === "undefined") {
|
||||
globalThis.requestIdleCallback = (cb) => cb();
|
||||
globalThis.cancelIdleCallback = () => {};
|
||||
if (globalThis.window) {
|
||||
globalThis.window.requestIdleCallback = globalThis.requestIdleCallback;
|
||||
globalThis.window.cancelIdleCallback = globalThis.cancelIdleCallback;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof globalThis.window.crypto === "undefined" && typeof globalThis.crypto !== "undefined") {
|
||||
globalThis.window.crypto = globalThis.crypto;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user