import { describe, it, expect, vi, beforeEach } from 'vitest'; interface ChromeStub { runtime: { sendMessage: ReturnType }; } interface GlobalWithChrome { chrome?: ChromeStub; MediaRecorder?: { isTypeSupported: (mime: string) => boolean }; } describe('codec strict mode', () => { beforeEach(() => { vi.resetModules(); (globalThis as unknown as GlobalWithChrome).chrome = { runtime: { sendMessage: vi.fn() }, }; }); it('throws on unsupported vp9 and emits RECORDING_ERROR', async () => { (globalThis as unknown as GlobalWithChrome).MediaRecorder = { isTypeSupported: vi.fn().mockReturnValue(false), }; const mod = await import('../../src/offscreen/recorder'); expect(() => mod.assertCodecSupported()).toThrow(/vp9 unsupported/); const stub = (globalThis as unknown as GlobalWithChrome).chrome!; expect(stub.runtime.sendMessage).toHaveBeenCalledWith( expect.objectContaining({ type: 'RECORDING_ERROR' }) ); }); it('does not throw when vp9 IS supported', async () => { (globalThis as unknown as GlobalWithChrome).MediaRecorder = { isTypeSupported: vi.fn().mockReturnValue(true), }; const mod = await import('../../src/offscreen/recorder'); expect(() => mod.assertCodecSupported()).not.toThrow(); const stub = (globalThis as unknown as GlobalWithChrome).chrome!; expect(stub.runtime.sendMessage).not.toHaveBeenCalledWith( expect.objectContaining({ type: 'RECORDING_ERROR' }) ); }); });