/** * Vitest setup: registers jest-dom matchers, provides a working * `localStorage` and cleans up the DOM after every test (React Testing * Library auto-cleanup needs this when globals are disabled). */ import '@testing-library/jest-dom/vitest'; import { cleanup } from '@testing-library/react'; import { afterEach } from 'vitest'; /** * In-memory Storage. Node >= 22 exposes an experimental `localStorage` * global that is `undefined` without `--localstorage-file`, and the jsdom * environment does not override it — so the auth tests (which persist the * JWT under AUTH_TOKEN) get a real storage implementation here. */ class MemoryStorage implements Storage { private store = new Map(); get length(): number { return this.store.size; } clear(): void { this.store.clear(); } getItem(key: string): string | null { return this.store.has(key) ? this.store.get(key)! : null; } key(index: number): string | null { return Array.from(this.store.keys())[index] ?? null; } removeItem(key: string): void { this.store.delete(key); } setItem(key: string, value: string): void { this.store.set(key, String(value)); } } Object.defineProperty(globalThis, 'localStorage', { configurable: true, writable: true, value: new MemoryStorage(), }); afterEach(() => { cleanup(); });