Skip to content

Commit 30751d7

Browse files
committed
fix(cli): snapshot prints a progress line as each frame starts
1 parent 8b1f88b commit 30751d7

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
2+
import { tmpdir } from "node:os";
3+
import { join } from "node:path";
4+
import { afterAll, expect, it, vi } from "vitest";
5+
import snapshotCommand from "./snapshot.js";
6+
7+
const root = mkdtempSync(join(tmpdir(), "hf-snapshot-progress-"));
8+
9+
afterAll(() => rmSync(root, { recursive: true, force: true }));
10+
11+
it("prints a progress line on stderr as each frame starts, and keeps stdout one --json envelope", async () => {
12+
writeFileSync(
13+
join(root, "index.html"),
14+
`<!doctype html><html><body style="margin:0;background:#000">
15+
<div id="root" data-composition-id="main" data-start="0" data-duration="5" data-width="320" data-height="180" style="width:320px;height:180px"></div>
16+
<script>
17+
window.__timelines = { main: { pause() {}, time() { return 0; }, duration() { return 5; }, seek() {} } };
18+
</script></body></html>`,
19+
);
20+
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
21+
const error = vi.spyOn(console, "error").mockImplementation(() => undefined);
22+
vi.spyOn(console, "warn").mockImplementation(() => undefined);
23+
try {
24+
await snapshotCommand.run?.({
25+
args: {
26+
dir: root,
27+
at: "1,2.5",
28+
end: false,
29+
json: true,
30+
output: join(root, "out"),
31+
describe: "false",
32+
"browser-gpu": false,
33+
},
34+
} as never);
35+
const progress = error.mock.calls
36+
.map(([line]) => String(line))
37+
.filter((line) => line.startsWith("[hyperframes] snapshot:"));
38+
39+
expect(progress).toEqual([
40+
"[hyperframes] snapshot: frame 1/2 at 1s",
41+
"[hyperframes] snapshot: frame 2/2 at 2.5s",
42+
]);
43+
expect(log).toHaveBeenCalledTimes(1);
44+
expect(JSON.parse(String(log.mock.calls[0]?.[0])).frames).toHaveLength(2);
45+
} finally {
46+
vi.restoreAllMocks();
47+
}
48+
}, 120_000);

‎packages/cli/src/commands/snapshot.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ async function captureSnapshots(
930930

931931
for (let i = 0; i < positions.length; i++) {
932932
const time = positions[i]!;
933+
console.error(`[hyperframes] snapshot: frame ${i + 1}/${positions.length} at ${time}s`);
933934

934935
const seekOptions = { exactTime: true, waitForImagesMs: SCREENSHOT_IMAGE_WAIT_MS };
935936
await atStep(`seeking to ${time}s, frame ${i + 1} of ${positions.length}`, () =>

0 commit comments

Comments
 (0)