mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 20:42:02 +00:00
7d2a22c45a
Co-authored-by: Pablo F.G <pablo.fernandez@prowler.com> Co-authored-by: César Arroba <19954079+cesararroba@users.noreply.github.com>
88 lines
1.8 KiB
TypeScript
88 lines
1.8 KiB
TypeScript
import "@testing-library/jest-dom/vitest";
|
|
|
|
// An ambient UI_CLOUD_ENABLED in a developer's shell would silently flip
|
|
// every test that relies on the OSS default — clear it.
|
|
delete process.env.UI_CLOUD_ENABLED;
|
|
|
|
class MockStorage implements Storage {
|
|
private readonly store = new Map<string, string>();
|
|
|
|
get length() {
|
|
return this.store.size;
|
|
}
|
|
|
|
clear() {
|
|
this.store.clear();
|
|
}
|
|
|
|
getItem(key: string) {
|
|
return this.store.get(key) ?? null;
|
|
}
|
|
|
|
key(index: number) {
|
|
return Array.from(this.store.keys())[index] ?? null;
|
|
}
|
|
|
|
removeItem(key: string) {
|
|
this.store.delete(key);
|
|
}
|
|
|
|
setItem(key: string, value: string) {
|
|
this.store.set(key, value);
|
|
}
|
|
}
|
|
|
|
const localStorageMock = new MockStorage();
|
|
const sessionStorageMock = new MockStorage();
|
|
|
|
Object.defineProperty(globalThis, "localStorage", {
|
|
value: localStorageMock,
|
|
configurable: true,
|
|
});
|
|
|
|
Object.defineProperty(window, "localStorage", {
|
|
value: localStorageMock,
|
|
configurable: true,
|
|
});
|
|
|
|
Object.defineProperty(globalThis, "sessionStorage", {
|
|
value: sessionStorageMock,
|
|
configurable: true,
|
|
});
|
|
|
|
Object.defineProperty(window, "sessionStorage", {
|
|
value: sessionStorageMock,
|
|
configurable: true,
|
|
});
|
|
|
|
const emptyClientRects = [] as unknown as DOMRectList;
|
|
const emptyRect = {
|
|
x: 0,
|
|
y: 0,
|
|
width: 0,
|
|
height: 0,
|
|
top: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
left: 0,
|
|
toJSON: () => ({}),
|
|
} as DOMRect;
|
|
|
|
if (!Range.prototype.getClientRects) {
|
|
Range.prototype.getClientRects = () => emptyClientRects;
|
|
}
|
|
|
|
if (!Range.prototype.getBoundingClientRect) {
|
|
Range.prototype.getBoundingClientRect = () => emptyRect;
|
|
}
|
|
|
|
class MockResizeObserver implements ResizeObserver {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
}
|
|
|
|
if (!globalThis.ResizeObserver) {
|
|
globalThis.ResizeObserver = MockResizeObserver;
|
|
}
|