diff --git a/tests/offscreen/codec-check.test.ts b/tests/offscreen/codec-check.test.ts new file mode 100644 index 0000000..ea52caa --- /dev/null +++ b/tests/offscreen/codec-check.test.ts @@ -0,0 +1,43 @@ +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' }) + ); + }); +});