MAESTRO: add analysis cache hook

This commit is contained in:
Mariusz Banach
2026-02-18 03:41:42 +01:00
parent 07ee139a00
commit c039a8a432
5 changed files with 227 additions and 3 deletions

52
frontend/vitest.setup.ts Normal file
View File

@@ -0,0 +1,52 @@
const createLocalStorageMock = () => {
let store = new Map<string, string>();
return {
get length() {
return store.size;
},
clear() {
store.clear();
},
getItem(key: string) {
return store.has(key) ? store.get(key) ?? null : null;
},
key(index: number) {
if (index < 0 || index >= store.size) {
return null;
}
return Array.from(store.keys())[index] ?? null;
},
removeItem(key: string) {
store.delete(key);
},
setItem(key: string, value: string) {
store.set(String(key), String(value));
},
};
};
const ensureLocalStorage = () => {
const target = typeof window !== "undefined" ? window : globalThis;
const current = target.localStorage as Storage | undefined;
if (!current || typeof current.clear !== "function") {
const mock = createLocalStorageMock();
Object.defineProperty(target, "localStorage", {
value: mock,
configurable: true,
enumerable: true,
writable: false,
});
if (target !== globalThis) {
Object.defineProperty(globalThis, "localStorage", {
value: mock,
configurable: true,
enumerable: true,
writable: false,
});
}
}
};
ensureLocalStorage();