test(studio): a test chrome launch that fails with a non-error names what it holds (#8305)

This commit is contained in:
Miguel Ángel
2026-11-20 18:46:16 +00:00
committed by GitHub
parent 44d805c444
commit 0ecb6671f1
2 changed files with 16 additions and 1 deletions
@@ -60,6 +60,19 @@ describe("launchTestChrome", () => {
}
});
it("names a launch failure that is not an Error by what it holds", async () => {
const error = vi.spyOn(console, "error").mockImplementation(() => {});
vi.spyOn(console, "info").mockImplementation(() => {});
try {
// Puppeteer rejects a dropped DevTools socket with an event that holds the Error.
const dropped = { error: new Error("read ECONNRESET") };
await expect(launchTestChrome(vi.fn().mockRejectedValue(dropped))).rejects.toBe(dropped);
expect(String(error.mock.calls[0]?.[0])).toContain("read ECONNRESET");
} finally {
vi.restoreAllMocks();
}
});
it("stops after the second stuck launch and preserves its error", async () => {
const failure = new TimeoutError("still stuck");
const launch = vi.fn().mockRejectedValue(failure);
+3 -1
View File
@@ -1,5 +1,6 @@
import { readFileSync } from "node:fs";
import { createRequire } from "node:module";
import { inspect } from "node:util";
import puppeteer, { TimeoutError, type Browser, type Page } from "puppeteer-core";
import { browserVersion, findSystemChrome } from "../vite.browser";
@@ -38,7 +39,8 @@ export async function launchTestChrome(
return browser;
} catch (error) {
const elapsed = Date.now() - startedAt;
const reason = error instanceof Error ? error.message : String(error);
const reason =
error instanceof Error ? error.message : inspect(error, { breakLength: Infinity });
console.error(
`[studio-test-chrome] launch ${attempt}/${LAUNCH_ATTEMPTS} failed after ${elapsed} ms: ${reason}`,
);