import { expect, test } from "bun:test"; import { join } from "node:path"; import { readFile, stat } from "node:fs/promises"; import { extractFrame, probeDuration, putFile } from "../src/media"; import { renderPdf } from "../src/pdf"; import { makePdf, makeVideo, PYTHON, tmp } from "./fixtures"; const tools = { ffmpeg: "ffmpeg", ffprobe: "ffprobe" }; test("duration and frame extraction on a tiny clip", async () => { const d = await tmp(); await makeVideo(join(d, "a.mp4"), 2); expect(await probeDuration(tools, join(d, "a.mp4"))).toBe(2); await extractFrame(tools, join(d, "a.mp4"), join(d, "out", "f.jpg")); expect((await stat(join(d, "out", "f.jpg"))).size).toBeGreaterThan(100); }); test("putFile copies and links without touching the original", async () => { const d = await tmp(); await makeVideo(join(d, "sp ace", "ö.mp4"), 1); const before = await readFile(join(d, "sp ace", "ö.mp4")); await putFile(join(d, "sp ace", "ö.mp4"), join(d, "c", "x.mp4"), "copy"); await putFile(join(d, "sp ace", "ö.mp4"), join(d, "l", "x.mp4"), "link"); expect(Buffer.compare(await readFile(join(d, "c", "x.mp4")), before)).toBe(0); expect((await stat(join(d, "l", "x.mp4"))).ino).toBe((await stat(join(d, "sp ace", "ö.mp4"))).ino); }); test("renderPdf writes page images and text", async () => { const d = await tmp(); await makePdf(join(d, "deck.pdf"), ["Hello alpha", "Second beta"]); const seen: number[] = []; const r = await renderPdf(PYTHON, join(d, "deck.pdf"), join(d, "out"), { onPage: (p) => seen.push(p) }); expect(r.pages).toBe(2); expect(seen).toEqual([1, 2]); expect((await stat(join(d, "out", "p-002.jpg"))).size).toBeGreaterThan(100); const text = JSON.parse(await readFile(join(d, "out", "text.json"), "utf8")); expect(text[0].text).toContain("Hello alpha"); });