|
| 1 | +import { EventEmitter } from "node:events"; |
| 2 | +import { Readable } from "node:stream"; |
| 3 | +import { describe, expect, it, vi } from "vitest"; |
| 4 | + |
| 5 | +const { spawnMock, processFrameMock, closeSessionMock } = vi.hoisted(() => ({ |
| 6 | + spawnMock: vi.fn(), |
| 7 | + processFrameMock: vi.fn(async () => ({ fg: Buffer.alloc(4) })), |
| 8 | + closeSessionMock: vi.fn(async () => undefined), |
| 9 | +})); |
| 10 | + |
| 11 | +vi.mock("node:child_process", () => ({ spawn: spawnMock })); |
| 12 | +vi.mock("../browser/ffmpeg.js", () => ({ |
| 13 | + findFFmpeg: () => "/fake/bin/ffmpeg", |
| 14 | + findFFprobe: () => "/fake/bin/ffprobe", |
| 15 | + getFFmpegInstallHint: () => "install ffmpeg", |
| 16 | +})); |
| 17 | +vi.mock("./inference.js", () => ({ |
| 18 | + createSession: async () => ({ |
| 19 | + provider: "test", |
| 20 | + process: processFrameMock, |
| 21 | + close: closeSessionMock, |
| 22 | + }), |
| 23 | +})); |
| 24 | +vi.mock("@hyperframes/engine", () => ({ |
| 25 | + DEFAULT_VP9_CPU_USED: 4, |
| 26 | + renderProvenanceArgs: () => [], |
| 27 | + extractMediaMetadata: async () => ({ width: 1, height: 1, fps: 1, durationSeconds: 1 }), |
| 28 | +})); |
| 29 | + |
| 30 | +import { render } from "./pipeline.js"; |
| 31 | + |
| 32 | +function fakeFfmpeg(stdout: Readable) { |
| 33 | + const proc = new EventEmitter() as EventEmitter & { |
| 34 | + stdout: Readable; |
| 35 | + stderr: EventEmitter; |
| 36 | + stdin: EventEmitter & { write: ReturnType<typeof vi.fn>; end: ReturnType<typeof vi.fn> }; |
| 37 | + kill: ReturnType<typeof vi.fn>; |
| 38 | + }; |
| 39 | + proc.stdout = stdout; |
| 40 | + proc.stderr = new EventEmitter(); |
| 41 | + proc.stdin = Object.assign(new EventEmitter(), { write: vi.fn(() => true), end: vi.fn() }); |
| 42 | + proc.kill = vi.fn(); |
| 43 | + queueMicrotask(() => proc.emit("exit", 0, null)); |
| 44 | + return proc; |
| 45 | +} |
| 46 | + |
| 47 | +describe("background-removal FFmpeg child-process options", () => { |
| 48 | + it("hides every FFmpeg console window", async () => { |
| 49 | + spawnMock |
| 50 | + .mockImplementationOnce(() => fakeFfmpeg(Readable.from([Buffer.alloc(3)]))) |
| 51 | + .mockImplementationOnce(() => fakeFfmpeg(Readable.from([]))); |
| 52 | + |
| 53 | + await render({ inputPath: "/tmp/input.mp4", outputPath: "/tmp/output.webm" }); |
| 54 | + |
| 55 | + expect(spawnMock).toHaveBeenCalledTimes(2); |
| 56 | + for (const call of spawnMock.mock.calls) { |
| 57 | + expect(call[2]).toEqual(expect.objectContaining({ windowsHide: true })); |
| 58 | + } |
| 59 | + }); |
| 60 | +}); |
0 commit comments