Milestone v1 (v2.0.0): Mokosh — Session Capture #1
43
tests/offscreen/codec-check.test.ts
Normal file
43
tests/offscreen/codec-check.test.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
|
||||||
|
interface ChromeStub {
|
||||||
|
runtime: { sendMessage: ReturnType<typeof vi.fn> };
|
||||||
|
}
|
||||||
|
|
||||||
|
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' })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user