mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(cli): capture takes a refused screenshot once more before naming it * fix(cli): keep the screenshot retry's doc to one line * test(cli): refuse the same capture shot twice now that one refusal is retried
38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { screenshotOnceMore } from "./screenshotOnceMore.js";
|
|
|
|
const dropped = () =>
|
|
new Error("Protocol error (Page.captureScreenshot): Unable to capture screenshot");
|
|
|
|
describe("screenshotOnceMore", () => {
|
|
it("shoots again when Chrome drops the screenshot mid-paint", async () => {
|
|
const shoot = vi.fn().mockRejectedValueOnce(dropped()).mockResolvedValueOnce("png");
|
|
await expect(screenshotOnceMore(shoot)).resolves.toBe("png");
|
|
expect(shoot).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("gives up after the second drop", async () => {
|
|
const shoot = vi.fn().mockRejectedValue(dropped());
|
|
await expect(screenshotOnceMore(shoot)).rejects.toThrow(/Unable to capture screenshot/);
|
|
expect(shoot).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("reports the first drop when the second try fails differently", async () => {
|
|
const first = dropped();
|
|
const shoot = vi
|
|
.fn()
|
|
.mockRejectedValueOnce(first)
|
|
.mockRejectedValueOnce(new Error("Target closed"));
|
|
await expect(screenshotOnceMore(shoot)).rejects.toBe(first);
|
|
});
|
|
|
|
it("does not retry a screenshot that fails the same way every time", async () => {
|
|
const zero = new Error(
|
|
"Protocol error (Page.captureScreenshot): Cannot take screenshot with 0 width.",
|
|
);
|
|
const shoot = vi.fn().mockRejectedValue(zero);
|
|
await expect(screenshotOnceMore(shoot)).rejects.toBe(zero);
|
|
expect(shoot).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|