|
| 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); |
0 commit comments