Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
test(web): pin commit page timings, phases and heartbeat time with a controlled clock
Richie McIlroy16178e306d06
diff --git a/apps/web/__tests__/unit/finalize-desktop-recording.test.ts b/apps/web/__tests__/unit/finalize-desktop-recording.test.tsindex 111e8f514..96f01374d 100644--- a/apps/web/__tests__/unit/finalize-desktop-recording.test.ts+++ b/apps/web/__tests__/unit/finalize-desktop-recording.test.ts@@ -580,31 +580,73 @@ describe("bounded source commitment steps", () => {});it("logs the timing of every commit page without storage keys", async () => {- mocks.commitSource.mockImplementation(async (_video, checkpoint) =>- checkpoint.revision === 1- ? { source }- : advanceCheckpoint(_video, checkpoint),+ let clock = 0;+ const now = vi.spyOn(performance, "now").mockImplementation(() => clock);+ mocks.commitSource.mockImplementation(+ async (_video, checkpoint, _verification, onProgress) => {+ clock += 5;+ await onProgress();+ clock += 100;+ if (checkpoint.revision === 1) return { source };+ return {+ checkpoint: {+ ...checkpoint,+ phase: "copy",+ revision: checkpoint.revision + 1,+ },+ };+ },);+ mocks.heartbeat.mockImplementation(async () => {+ clock += 7;+ return true;+ });+ mocks.saveCheckpoint.mockImplementation(async (_attempt, checkpoint) => {+ clock += 20;+ withCurrent({ output: checkpoint });+ return true;+ });+ mocks.persist.mockImplementation(async (_attempt, savedSource) => {+ clock += 30;+ withCurrent({ source: savedSource, state: "processing" });+ return true;+ });const info = vi.spyOn(console, "info").mockImplementation(() => {});try {expect(await commitDesktopRecordingAttempt(fixture)).toBe("ready");const events = info.mock.calls.map(([line]) => JSON.parse(String(line))).filter((event) => event.event === "desktop_source_commit_advance");- expect(events).toHaveLength(2);- expect(events[0]).toMatchObject({- videoId: "video",- attemptId: "attempt",- outcome: "progress",- });- expect(events[1]).toMatchObject({ next: "committed", outcome: "ready" });- for (const event of events) {- for (const key of ["loadMs", "heartbeatMs", "advanceMs", "persistMs"])- expect(event[key]).toBeGreaterThanOrEqual(0);- expect(JSON.stringify(event)).not.toContain(source.inventoryKey);- }+ expect(events).toEqual([+ {+ event: "desktop_source_commit_advance",+ videoId: "video",+ attemptId: "attempt",+ phase: "plan",+ next: "copy",+ outcome: "progress",+ loadMs: 0,+ heartbeatMs: 7,+ advanceMs: 112,+ persistMs: 20,+ },+ {+ event: "desktop_source_commit_advance",+ videoId: "video",+ attemptId: "attempt",+ phase: "copy",+ next: "committed",+ outcome: "ready",+ loadMs: 0,+ heartbeatMs: 7,+ advanceMs: 112,+ persistMs: 30,+ },+ ]);+ expect(JSON.stringify(events)).not.toContain(source.inventoryKey);} finally {info.mockRestore();+ now.mockRestore();}});