import '@testing-library/jest-dom'; import { webcrypto } from 'node:crypto'; import { beforeEach } from 'vitest'; // jsdom lacks WebCrypto subtle — polyfill from Node if (!globalThis.crypto?.subtle) { Object.defineProperty(globalThis, 'crypto', { value: webcrypto }); } // jsdom lacks ResizeObserver (needed by Recharts) class ResizeObserverMock { observe() {} unobserve() {} disconnect() {} } globalThis.ResizeObserver = ResizeObserverMock as unknown as typeof ResizeObserver; // structuredClone polyfill for older jsdom if (!globalThis.structuredClone) { globalThis.structuredClone = (o: unknown) => JSON.parse(JSON.stringify(o)); } // Silence "not implemented: navigation" warnings from jsdom const originalWarn = console.warn; console.warn = (...args: unknown[]) => { if (typeof args[0] === 'string' && args[0].includes('Not implemented')) return; originalWarn(...args); }; // Reset cookies between tests beforeEach(() => { document.cookie.split(';').forEach((c) => { const name = c.split('=')[0].trim(); if (name) document.cookie = `${name}=; max-age=0; path=/`; }); localStorage.clear(); });