// Global test setup: a minimal stand-in for Firefox's `browser` global with an // in-memory storage.local, so storage.ts and the transport picker run under vitest. import { beforeEach } from 'vitest'; function makeBrowserShim() { const store = new Map(); const local = { get: async (keys?: string | string[] | Record | null) => { if (keys == null) return Object.fromEntries(store); const names = typeof keys === 'string' ? [keys] : Array.isArray(keys) ? keys : Object.keys(keys); const out: Record = {}; for (const k of names) if (store.has(k)) out[k] = store.get(k); return out; }, set: async (obj: Record) => { for (const [k, v] of Object.entries(obj)) store.set(k, v); }, remove: async (keys: string | string[]) => { for (const k of typeof keys === 'string' ? [keys] : keys) store.delete(k); }, clear: async () => { store.clear(); }, }; return { storage: { local }, runtime: { getURL: (path = '/') => `moz-extension://11111111-2222-3333-4444-555555555555${path}`, connectNative: () => { throw new Error('browser.runtime.connectNative was not stubbed for this test'); }, }, }; } // eslint-disable-next-line @typescript-eslint/no-explicit-any (globalThis as any).browser = makeBrowserShim(); beforeEach(async () => { await browser.storage.local.clear(); });