// Global test setup: a mock of `webextension-polyfill` with an in-memory // storage.local, so storage.ts and the transport picker run without a browser. import { beforeEach, vi } from 'vitest'; vi.mock('webextension-polyfill', () => { 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 { default: { 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'); }, }, }, }; }); beforeEach(async () => { const browser = (await import('webextension-polyfill')).default; await browser.storage.local.clear(); });