UNPKG

av-kit

Version:

AVFoundation Recorder kit for Node.js

84 lines (75 loc) 2.32 kB
import { EventEmitter } from "events"; // Mock for child_process.spawn export class MockChildProcess extends EventEmitter { public pid = 12345; public stdin = new EventEmitter(); public stdout = new EventEmitter(); public stderr = new EventEmitter(); public killed = false; kill() { this.killed = true; this.emit("close", 0); return true; } } // Mock for path module functions export const pathMock = { join: jest.fn((...paths: string[]) => paths.join("/")), resolve: jest.fn((...paths: string[]) => paths.join("/")), }; // Mock for fs/promises functions export const fsMock = { mkdir: jest.fn().mockResolvedValue(undefined), access: jest.fn().mockResolvedValue(undefined), stat: jest.fn().mockResolvedValue({ isFile: () => true, size: 1024, }), }; // Mock for child_process functions export const childProcessMock = { spawn: jest.fn(() => { const proc = new MockChildProcess(); setTimeout(() => { proc.emit("spawn"); }, 10); return proc; }), }; // Mock for device detection responses export const devicesMock = { displays: [ { id: "display1", name: "Main Display" }, { id: "display2", name: "Secondary Display" }, ], cameras: [ { id: "camera1", name: "FaceTime HD Camera" }, { id: "camera2", name: "External Camera" }, ], microphones: [ { id: "mic1", name: "Built-in Microphone" }, { id: "mic2", name: "External Microphone" }, ], }; // Mock implementation of execFileSync for device detection export const execFileSyncMock = jest.fn((command: string, args: string[]) => { if (args.includes("-list_devices") && args.includes("true")) { return Buffer.from(` [AVFoundation input device @ 0x7f8c7f5c5000] AVFoundation video devices: [AVFoundation input device @ 0x7f8c7f5c5000] [0] FaceTime HD Camera [AVFoundation input device @ 0x7f8c7f5c5000] [1] External Camera [AVFoundation input device @ 0x7f8c7f5c5000] AVFoundation audio devices: [AVFoundation input device @ 0x7f8c7f5c5000] [0] Built-in Microphone [AVFoundation input device @ 0x7f8c7f5c5000] [1] External Microphone `); } return Buffer.from(""); }); // Mock for video metadata export const videoMetadataMock = { dimensions: { width: 1920, height: 1080, }, durationInSeconds: 60, };