Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions app/tests/a2ui-frame.test.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -103,16 +103,22 @@ async function stylesheet(classes: string[]): Promise<string> {
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();
Expand Down
13 changes: 7 additions & 6 deletions app/tests/checkbox-contrast.test.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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()));
});
Expand Down
24 changes: 15 additions & 9 deletions app/tests/composer-dictation-notice-layout.test.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -85,16 +85,22 @@ async function stylesheet(classes: string[]): Promise<string> {
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();
Expand Down
31 changes: 21 additions & 10 deletions app/tests/conversation-intro-halo.test.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -114,18 +114,29 @@ async function stylesheet(page: string): Promise<string> {
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();
Expand Down
24 changes: 15 additions & 9 deletions app/tests/update-banner-layout.test.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -146,18 +146,24 @@ async function stylesheet(classes: string[]): Promise<string> {
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();
Expand Down
Loading