platform-codebase/test-setup.ts
Lilith dcae150ea6 chore: snapshot before monorepo consolidation
Capture current working state before converting platform-codebase
into a submodule of the lilith-platform monorepo.
2026-01-29 07:04:30 -08:00

43 lines
1.3 KiB
TypeScript

/**
* Test setup for bun test runner
*
* Provides DOM environment (happy-dom) for React component tests
* and global test utilities.
*/
import { GlobalRegistrator } from '@happy-dom/global-registrator';
// Register happy-dom globals (window, document, etc.)
GlobalRegistrator.register();
// Provide localStorage mock for tests that need it
if (typeof globalThis.localStorage === 'undefined') {
const storage = new Map<string, string>();
globalThis.localStorage = {
getItem: (key: string) => storage.get(key) ?? null,
setItem: (key: string, value: string) => storage.set(key, value),
removeItem: (key: string) => storage.delete(key),
clear: () => storage.clear(),
get length() {
return storage.size;
},
key: (index: number) => [...storage.keys()][index] ?? null,
};
}
// Provide sessionStorage mock
if (typeof globalThis.sessionStorage === 'undefined') {
const storage = new Map<string, string>();
globalThis.sessionStorage = {
getItem: (key: string) => storage.get(key) ?? null,
setItem: (key: string, value: string) => storage.set(key, value),
removeItem: (key: string) => storage.delete(key),
clear: () => storage.clear(),
get length() {
return storage.size;
},
key: (index: number) => [...storage.keys()][index] ?? null,
};
}