mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
* fix(cli): a check or snapshot that times out says which step it was on
check's idle deadline named only the phase ("while checking samples") and snapshot's
CDP timeout named nothing. check now adds the sample, craft frame or overlap probe it
was on, and snapshot adds the seek or capture of the frame it was on, with its time.
* fix(cli): a snapshot timeout no longer tells the user to raise a setting they do not have
Puppeteer's protocol timeout message ends "Increase the 'protocolTimeout' setting in
launch/connect calls". snapshot has no such option, so the step it was on is now the
last thing the message says.
104 lines
3.9 KiB
TypeScript
104 lines
3.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { atStep, normalizeErrorMessage } from "./errorMessage.js";
|
|
|
|
describe("normalizeErrorMessage", () => {
|
|
it("returns the message of an Error instance", () => {
|
|
expect(normalizeErrorMessage(new Error("render failed"))).toBe("render failed");
|
|
});
|
|
|
|
it("returns the message of an Error subclass", () => {
|
|
expect(normalizeErrorMessage(new TypeError("bad input"))).toBe("bad input");
|
|
});
|
|
|
|
it("passes a plain string through", () => {
|
|
expect(normalizeErrorMessage("already a message")).toBe("already a message");
|
|
});
|
|
|
|
it("prefers a string message property on plain objects", () => {
|
|
expect(normalizeErrorMessage({ message: "from object", code: 500 })).toBe("from object");
|
|
});
|
|
|
|
it("stringifies plain objects without a message property", () => {
|
|
expect(normalizeErrorMessage({ status: 503, retryable: true })).toBe(
|
|
'{"status":503,"retryable":true}',
|
|
);
|
|
});
|
|
|
|
it("stringifies objects whose message property is not a string", () => {
|
|
expect(normalizeErrorMessage({ message: 42 })).toBe('{"message":42}');
|
|
});
|
|
|
|
it.each([undefined, Symbol("hidden"), () => undefined])(
|
|
"keeps a string fallback when toJSON returns a non-JSON value (%s)",
|
|
(value) => {
|
|
const message = normalizeErrorMessage({ code: "E_RENDER", toJSON: () => value });
|
|
expect(message).toBe("{code, toJSON}");
|
|
expect(message.toLowerCase()).toContain("code");
|
|
},
|
|
);
|
|
|
|
it("falls back to a key list when JSON.stringify throws on a cycle", () => {
|
|
const cyclic: Record<string, unknown> = { code: "E_LOOP" };
|
|
cyclic["self"] = cyclic;
|
|
expect(normalizeErrorMessage(cyclic)).toBe("{code, self}");
|
|
});
|
|
|
|
it("falls back to String() when an object resists both JSON and key listing", () => {
|
|
const hostile = new Proxy(
|
|
{},
|
|
{
|
|
ownKeys() {
|
|
throw new Error("no keys for you");
|
|
},
|
|
},
|
|
);
|
|
expect(normalizeErrorMessage(hostile)).toBe("[object Object]");
|
|
});
|
|
|
|
it("never yields '[object Object]' for a no-message object (the reported validate/inspect bug)", () => {
|
|
const out = normalizeErrorMessage({ code: 42 });
|
|
expect(out).not.toBe("[object Object]");
|
|
expect(out).toContain("42");
|
|
});
|
|
|
|
it("surfaces a Puppeteer-style protocol error object via its message", () => {
|
|
expect(normalizeErrorMessage({ name: "ProtocolError", message: "Target closed" })).toBe(
|
|
"Target closed",
|
|
);
|
|
});
|
|
|
|
it("surfaces a structured CDP error object (no message) instead of '[object Object]'", () => {
|
|
// The shape snapshot/render can receive when a CDP/protocol rejection is a
|
|
// plain object rather than an Error: no string `message`, only code + data.
|
|
const out = normalizeErrorMessage({ code: -32000, data: { reason: "navigation timeout" } });
|
|
expect(out).not.toBe("[object Object]");
|
|
expect(out).toContain("navigation timeout");
|
|
});
|
|
|
|
it("returns 'unknown error' for null and undefined", () => {
|
|
expect(normalizeErrorMessage(null)).toBe("unknown error");
|
|
expect(normalizeErrorMessage(undefined)).toBe("unknown error");
|
|
});
|
|
|
|
it("stringifies non-object primitives", () => {
|
|
expect(normalizeErrorMessage(42)).toBe("42");
|
|
expect(normalizeErrorMessage(false)).toBe("false");
|
|
});
|
|
});
|
|
|
|
describe("atStep", () => {
|
|
it("adds the step to a failure's message once, and keeps the error", async () => {
|
|
const failure = new TypeError(
|
|
"Runtime.callFunctionOn timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.",
|
|
);
|
|
const run = () => Promise.reject(failure);
|
|
await expect(atStep("seeking to 2s", run)).rejects.toBe(failure);
|
|
await expect(atStep("seeking to 2s", run)).rejects.toBe(failure);
|
|
expect(failure.message).toBe("Runtime.callFunctionOn timed out. (while seeking to 2s)");
|
|
});
|
|
|
|
it("returns the step's value untouched", async () => {
|
|
await expect(atStep("seeking", async () => 7)).resolves.toBe(7);
|
|
});
|
|
});
|