From 97286d0cd1743dd6514b6ccfc8de16a5b33e75db Mon Sep 17 00:00:00 2001 From: David McKay Date: Mon, 16 Nov 2026 10:34:08 -0800 Subject: [PATCH 1/2] Build the browser tests' pages and start Chromium before the tests, not in a timed hook A beforeAll gets 5 s. In a2ui-frame, update-banner-layout, composer-dictation-notice-layout, checkbox-contrast and conversation-intro-halo the setup bundles a page or builds a stylesheet and starts Chromium, which can take longer than that on a cold runner when the file is the first one bun test opens. The setup now runs at the top of each file and waits for the bundle and for Chromium's launch, which Playwright bounds itself, as transcript-rail-clearance does. --- app/tests/a2ui-frame.test.tsx | 24 ++++++++++------- app/tests/checkbox-contrast.test.tsx | 13 ++++----- .../composer-dictation-notice-layout.test.tsx | 24 ++++++++++------- app/tests/conversation-intro-halo.test.tsx | 27 ++++++++++++------- app/tests/update-banner-layout.test.tsx | 24 ++++++++++------- 5 files changed, 69 insertions(+), 43 deletions(-) diff --git a/app/tests/a2ui-frame.test.tsx b/app/tests/a2ui-frame.test.tsx index 772f008539..75d9fe1e18 100644 --- a/app/tests/a2ui-frame.test.tsx +++ b/app/tests/a2ui-frame.test.tsx @@ -1,4 +1,4 @@ -import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { afterAll, describe, expect, test } from "bun:test"; import { existsSync, mkdirSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import type { Browser, Page } from "playwright-core"; @@ -103,16 +103,22 @@ async function stylesheet(classes: string[]): Promise { return compiler.build(classes); } -let browser: Browser; -let script: string; - -beforeAll(async () => { - if (!asked) return; - script = await bundle(); +/** + * The page's script and the browser, ready before any test starts. This waits for the bundle to be + * built and for Chromium to say it has started (Playwright's own launch timeout bounds that), not + * on a hook's clock: a `beforeAll` gets 5 s, and on a cold runner the two can take longer. + */ +async function ready(): Promise<{ script: string; browser: Browser }> { + const script = await bundle(); const { chromium } = await import("playwright-core"); // The CI job installs full Chromium without the headless shell. - browser = await chromium.launch({ channel: "chromium" }); -}); + const browser = await chromium.launch({ channel: "chromium" }); + return { script, browser }; +} + +let browser: Browser; +let script: string; +if (asked) ({ script, browser } = await ready()); afterAll(async () => { await browser?.close(); diff --git a/app/tests/checkbox-contrast.test.tsx b/app/tests/checkbox-contrast.test.tsx index 9d4f5859b1..b1fb59da7e 100644 --- a/app/tests/checkbox-contrast.test.tsx +++ b/app/tests/checkbox-contrast.test.tsx @@ -1,4 +1,4 @@ -import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { afterAll, describe, expect, test } from "bun:test"; import { existsSync, mkdirSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import type { Browser, Page } from "playwright-core"; @@ -141,14 +141,15 @@ function contrast(a: Rgb, b: Rgb): number { return (light + 0.05) / (dark + 0.05); } +/** + * The page's script, built before any test starts. This waits for the bundle, not on a hook's + * clock: a `beforeAll` gets 5 s, and on a cold runner bundling can take longer. Each test starts + * its own browser, inside the test's own time. + */ let script: string; +if (asked) script = await bundle(); const browsers: Browser[] = []; -beforeAll(async () => { - if (!asked) return; - script = await bundle(); -}); - afterAll(async () => { await Promise.all(browsers.map((browser) => browser.close())); }); diff --git a/app/tests/composer-dictation-notice-layout.test.tsx b/app/tests/composer-dictation-notice-layout.test.tsx index e1e3fe0f79..f2f04b7622 100644 --- a/app/tests/composer-dictation-notice-layout.test.tsx +++ b/app/tests/composer-dictation-notice-layout.test.tsx @@ -1,4 +1,4 @@ -import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { afterAll, describe, expect, test } from "bun:test"; import { existsSync, mkdirSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import type { Browser, Page } from "playwright-core"; @@ -85,16 +85,22 @@ async function stylesheet(classes: string[]): Promise { return compiler.build(classes); } -let browser: Browser; -let script: string; - -beforeAll(async () => { - if (!asked) return; - script = await bundle(); +/** + * The page's script and the browser, ready before any test starts. This waits for the bundle to be + * built and for Chromium to say it has started (Playwright's own launch timeout bounds that), not + * on a hook's clock: a `beforeAll` gets 5 s, and on a cold runner the two can take longer. + */ +async function ready(): Promise<{ script: string; browser: Browser }> { + const script = await bundle(); const { chromium } = await import("playwright-core"); // The CI job installs full Chromium without the headless shell. - browser = await chromium.launch({ channel: "chromium" }); -}); + const browser = await chromium.launch({ channel: "chromium" }); + return { script, browser }; +} + +let browser: Browser; +let script: string; +if (asked) ({ script, browser } = await ready()); afterAll(async () => { await browser?.close(); diff --git a/app/tests/conversation-intro-halo.test.tsx b/app/tests/conversation-intro-halo.test.tsx index 36487863a3..e2ff4872ab 100644 --- a/app/tests/conversation-intro-halo.test.tsx +++ b/app/tests/conversation-intro-halo.test.tsx @@ -1,4 +1,4 @@ -import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { afterAll, describe, expect, test } from "bun:test"; import { existsSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; @@ -114,18 +114,25 @@ async function stylesheet(page: string): Promise { return compiler.build(classes); } +/** + * The page, its stylesheet and the browser, ready before any test starts. This waits for Tailwind + * to build the stylesheet and for Chromium to say it has started (Playwright's own launch timeout + * bounds that), not on a hook's clock: a `beforeAll` gets 5 s, and on a cold runner the two can + * take longer. + */ +async function ready(): Promise<{ page: string; css: string; browser: Browser }> { + const page = markup(); + const css = await stylesheet(page); + const { chromium } = await import("playwright-core"); + // The CI job installs full Chromium without the headless shell. + const browser = await chromium.launch({ channel: "chromium" }); + return { page, css, browser }; +} + let browser: Browser; let page: string; let css: string; - -beforeAll(async () => { - if (!asked) return; - page = markup(); - css = await stylesheet(page); - const { chromium } = await import("playwright-core"); - // The CI job installs full Chromium without the headless shell. - browser = await chromium.launch({ channel: "chromium" }); -}); +if (asked) ({ page, css, browser } = await ready()); afterAll(async () => { await browser?.close(); diff --git a/app/tests/update-banner-layout.test.tsx b/app/tests/update-banner-layout.test.tsx index c920291992..485f6ae37e 100644 --- a/app/tests/update-banner-layout.test.tsx +++ b/app/tests/update-banner-layout.test.tsx @@ -1,4 +1,4 @@ -import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { afterAll, describe, expect, test } from "bun:test"; import { existsSync, mkdirSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import type { Browser, Page } from "playwright-core"; @@ -146,18 +146,24 @@ async function stylesheet(classes: string[]): Promise { return compiler.build(classes); } +/** + * The page's script and the browser, ready before any test starts. This waits for the bundle to be + * built and for Chromium to say it has started (Playwright's own launch timeout bounds that), not + * on a hook's clock: a `beforeAll` gets 5 s, and on a cold runner the two can take longer. + */ +async function ready(): Promise<{ script: string; browser: Browser }> { + const script = await bundle(); + const { chromium } = await import("playwright-core"); + // The CI job installs full Chromium without the headless shell. + const browser = await chromium.launch({ channel: "chromium" }); + return { script, browser }; +} + let browser: Browser; let script: string; /** The classes every state's banner wears, gathered once so one stylesheet styles them all. */ let css: string; - -beforeAll(async () => { - if (!asked) return; - script = await bundle(); - const { chromium } = await import("playwright-core"); - // The CI job installs full Chromium without the headless shell. - browser = await chromium.launch({ channel: "chromium" }); -}); +if (asked) ({ script, browser } = await ready()); afterAll(async () => { await browser?.close(); From c8d85b504627b4493d237e26ead9ac0359022c62 Mon Sep 17 00:00:00 2001 From: David McKay Date: Mon, 16 Nov 2026 10:36:24 -0800 Subject: [PATCH 2/2] Format conversation-intro-halo's setup as biome lays it out --- app/tests/conversation-intro-halo.test.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/tests/conversation-intro-halo.test.tsx b/app/tests/conversation-intro-halo.test.tsx index e2ff4872ab..4aa88ff48d 100644 --- a/app/tests/conversation-intro-halo.test.tsx +++ b/app/tests/conversation-intro-halo.test.tsx @@ -120,7 +120,11 @@ async function stylesheet(page: string): Promise { * bounds that), not on a hook's clock: a `beforeAll` gets 5 s, and on a cold runner the two can * take longer. */ -async function ready(): Promise<{ page: string; css: string; browser: Browser }> { +async function ready(): Promise<{ + page: string; + css: string; + browser: Browser; +}> { const page = markup(); const css = await stylesheet(page); const { chromium } = await import("playwright-core");