Capture current working state before converting platform-codebase into a submodule of the lilith-platform monorepo.
43 lines
1.3 KiB
TypeScript
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,
|
|
};
|
|
}
|