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:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-05 23:04:21 +00:00
1 parent 88cca17de0
commit 614e30a61a
1 file changed
+10
+10
View File
@@ -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;
}