repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
scripts/e2e-requirements.test.ts
Rawimport { afterEach, expect, it, vi } from "vitest";
const { execFileMock } = vi.hoisted(() => ({ execFileMock: vi.fn() }));
vi.mock("node:child_process", async (importOriginal) => ({
...(await importOriginal<typeof import("node:child_process")>()),
execFileSync: execFileMock,
}));
import { requireVideoTools } from "./e2e.ts";
afterEach(() => vi.resetAllMocks());
it("fails when ffmpeg is missing", () => {
execFileMock.mockImplementation(() => {
throw Object.assign(new Error("missing"), { code: "ENOENT" });
});
expect(requireVideoTools).toThrow("require a working ffmpeg binary on PATH");
});
it("fails when ffmpeg lacks the required VP9 encoder", () => {
execFileMock.mockReturnValue(" V....D libaom-av1 AV1 encoder\n");
expect(requireVideoTools).toThrow(
"require ffmpeg with the libvpx-vp9 encoder",
);
expect(execFileMock).toHaveBeenCalledTimes(1);
});
it("fails when ffprobe is missing", () => {
execFileMock.mockImplementation((binary) => {
if (binary === "ffmpeg") return " V....D libvpx-vp9 libvpx VP9\n";
throw Object.assign(new Error("missing"), { code: "ENOENT" });
});
expect(requireVideoTools).toThrow("require a working ffprobe binary on PATH");
});
it("accepts required system binaries with bounded probes", () => {
execFileMock.mockImplementation((binary) =>
binary === "ffmpeg"
? " V....D libvpx-vp9 libvpx VP9\n"
: "ffprobe version 9.0.2\n",
);
expect(requireVideoTools).not.toThrow();
expect(execFileMock).toHaveBeenNthCalledWith(
1,
"ffmpeg",
["-hide_banner", "-encoders"],
expect.objectContaining({ timeout: 5000, maxBuffer: 1024 * 1024 }),
);
expect(execFileMock).toHaveBeenNthCalledWith(
2,
"ffprobe",
["-version"],
expect.objectContaining({ timeout: 5000, maxBuffer: 1024 * 1024 }),
);
});