Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/cli/src/commands/snapshot-fonts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it, vi } from "vitest";

const mocks = vi.hoisted(() => ({
bundleToSingleHtml: vi.fn(async () => "<html><head></head><body>bundled</body></html>"),
injectDeterministicFontFaces: vi.fn(async (html: string) => `${html}\n<!-- fonts -->`),
}));

vi.mock("@hyperframes/core/compiler", () => ({
bundleToSingleHtml: mocks.bundleToSingleHtml,
}));
vi.mock("@hyperframes/producer", () => ({
injectDeterministicFontFaces: mocks.injectDeterministicFontFaces,
}));

import { prepareSnapshotHtml } from "./snapshot.js";

describe("prepareSnapshotHtml", () => {
it("injects the same deterministic font faces used by render", async () => {
const html = await prepareSnapshotHtml("/project");

expect(mocks.bundleToSingleHtml).toHaveBeenCalledWith("/project");
expect(mocks.injectDeterministicFontFaces).toHaveBeenCalledWith(
"<html><head></head><body>bundled</body></html>",
);
expect(html).toContain("<!-- fonts -->");
});
});
13 changes: 10 additions & 3 deletions packages/cli/src/commands/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ export function computeSnapshotTimes(
* Render key frames from a composition as PNG screenshots.
* The agent can Read these to verify its output visually.
*/
export async function prepareSnapshotHtml(projectDir: string): Promise<string> {
const [{ bundleToSingleHtml }, { injectDeterministicFontFaces }] = await Promise.all([
import("@hyperframes/core/compiler"),
import("@hyperframes/producer"),
]);
const bundledHtml = await bundleToSingleHtml(projectDir);
return injectDeterministicFontFaces(bundledHtml);
}

async function captureSnapshots(
projectDir: string,
opts: {
Expand All @@ -193,11 +202,9 @@ async function captureSnapshots(
zoomScale?: number;
},
): Promise<string[]> {
const { bundleToSingleHtml } = await import("@hyperframes/core/compiler");

const numFrames = opts.frames ?? 5;

const html = await bundleToSingleHtml(projectDir);
const html = await prepareSnapshotHtml(projectDir);
const server = await serveStaticProjectHtml(projectDir, html);

const savedPaths: string[] = [];
Expand Down
1 change: 1 addition & 0 deletions packages/producer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export {
localizeRemoteImageSources,
localizeRemoteFontFaces,
} from "./services/htmlCompiler.js";
export { injectDeterministicFontFaces } from "./services/deterministicFonts.js";

// ── Frame capture (lower-level) ─────────────────────────────────────────────
export {
Expand Down