import { describe, expect, test } from "bun:test"; import { existsSync } from "node:fs"; import { chromium } from "playwright-core"; import { buildPrintCss } from "./print-css"; import { PDFRenderer } from "./renderer"; // Real end-to-end render. Runs ONLY when a Chromium binary is already present // (e.g. a prior `playwright install chromium`). It never downloads a browser or // hits the network, so CI without a browser simply skips it. function chromiumAvailable(): boolean { try { const path = chromium.executablePath(); return typeof path === "string" && path.length > 0 && existsSync(path); } catch { return false; } } const available = chromiumAvailable(); describe("PDFRenderer smoke render", () => { test.skipIf(!available)( "renders a valid PDF from HTML using the local runtime", async () => { const html = `
Shared HTML to PDF pipeline.
`;
const renderer = new PDFRenderer({ runtime: "local" });
const bytes = await renderer.render(html);
expect(new TextDecoder().decode(bytes.slice(0, 5))).toBe("%PDF-");
expect(bytes.byteLength).toBeGreaterThan(1000);
},
30_000,
);
});