From 0ecb6671f14caf0036754d1f2db280db624dc058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Fri, 20 Nov 2026 18:46:16 +0000 Subject: [PATCH] test(studio): a test chrome launch that fails with a non-error names what it holds (#8305) --- packages/studio/tests/chromeTestUtils.test.ts | 13 +++++++++++++ packages/studio/tests/chromeTestUtils.ts | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/studio/tests/chromeTestUtils.test.ts b/packages/studio/tests/chromeTestUtils.test.ts index 700564fced..c4284ced76 100644 --- a/packages/studio/tests/chromeTestUtils.test.ts +++ b/packages/studio/tests/chromeTestUtils.test.ts @@ -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); diff --git a/packages/studio/tests/chromeTestUtils.ts b/packages/studio/tests/chromeTestUtils.ts index e517bc5ed1..9875c3166c 100644 --- a/packages/studio/tests/chromeTestUtils.ts +++ b/packages/studio/tests/chromeTestUtils.ts @@ -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}`, );