test(01-02): add RED codec-check tests
Two RED tests pin D-20 (codec strict-mode, no silent fallback): - 'throws on unsupported vp9 and emits RECORDING_ERROR' - 'does not throw when vp9 IS supported' vi.resetModules() between tests is critical: module-load side-effects (handshake + port connect) happen once per import, so isolation across the four test files depends on it. chrome.runtime is stubbed locally (no vitest-chrome dependency added, per threat T-1-NEW-02-01 — minimize supply chain for four test files). No 'as any' / no '@ts-ignore'; the cast is 'as unknown as T'. Plan 03 must export assertCodecSupported() from src/offscreen/recorder.ts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
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