|
| 1 | +import { EventEmitter } from "node:events"; |
| 2 | +import { describe, expect, it, vi } from "vitest"; |
| 3 | + |
| 4 | +// Hoisted so the mock factory below can reach it without a top-level variable. |
| 5 | +const { spawnMock } = vi.hoisted(() => ({ spawnMock: vi.fn() })); |
| 6 | + |
| 7 | +vi.mock("node:child_process", () => ({ spawn: spawnMock })); |
| 8 | +vi.mock("child_process", () => ({ spawn: spawnMock })); |
| 9 | + |
| 10 | +/** Minimal stand-in for the ChildProcess runFfmpeg awaits. */ |
| 11 | +function fakeFfmpeg() { |
| 12 | + const proc = new EventEmitter() as EventEmitter & Record<string, unknown>; |
| 13 | + proc.stdout = new EventEmitter(); |
| 14 | + proc.stderr = new EventEmitter(); |
| 15 | + proc.stdin = { write: vi.fn(), end: vi.fn() }; |
| 16 | + proc.kill = vi.fn(); |
| 17 | + proc.pid = 4242; |
| 18 | + queueMicrotask(() => proc.emit("close", 0, null)); |
| 19 | + return proc; |
| 20 | +} |
| 21 | + |
| 22 | +describe("runFfmpeg spawn options", () => { |
| 23 | + it("hides the console window so Windows renders do not flash terminals", async () => { |
| 24 | + // Regression for the Windows popup report: ffmpeg is a console-subsystem |
| 25 | + // binary, and Node defaults `windowsHide` to false, so every spawn opened a |
| 26 | + // visible window. A render shells out dozens of times across parallel |
| 27 | + // workers, which produced a burst of windows on the user's desktop. |
| 28 | + // Asserted on the options actually handed to spawn rather than on the |
| 29 | + // source text, so a future call site that drops the flag is caught by |
| 30 | + // behaviour. |
| 31 | + spawnMock.mockImplementation(() => fakeFfmpeg()); |
| 32 | + |
| 33 | + const { runFfmpeg } = await import("./runFfmpeg.js"); |
| 34 | + await runFfmpeg(["-version"]); |
| 35 | + |
| 36 | + expect(spawnMock).toHaveBeenCalledTimes(1); |
| 37 | + const options = spawnMock.mock.calls[0]?.[2] as { windowsHide?: boolean } | undefined; |
| 38 | + expect(options?.windowsHide).toBe(true); |
| 39 | + }); |
| 40 | +}); |
0 commit comments