Skip to content

Commit be67480

Browse files
matt2eclaude
andauthored
test(typeahead): serve the fixture pages as a build so cold loads fit (#2793)
## Summary `typeahead.spec.mjs` now builds its four fixture pages (`mentions`, `typeahead`, `emoji` and `messages`) once per worker in `beforeAll`. It serves the bundle with `build` and `preview` from `vite-server.mjs`. Before this change, it took its `baseURL` from the worker-scoped Vite dev server in `source-fixture.mjs`. The change is test-only: no assertions change, the navigation timeout is unchanged, and no browser cases are added or removed. ### Problem `Flake check (chromium, 11/11)` on #2507 failed `typeahead.spec.mjs:28` "closing-colon emoji conversion restores literal source and caret on undo" twice, with `TimeoutError: page.goto: Timeout 15000ms exceeded` on `/tests/fixtures/mentions.html?test-controls`. Both times it was the first test in the shard's second worker (16.4 s and 16.6 s), and the same worker's next 23 tests passed. #2507 doesn't touch that page's module graph; its `MessageRow` change only selects this spec into the 10× lane. - https://github.com/block/buzz-app/actions/runs/42195228817/job/127817183790 - https://github.com/block/buzz-app/actions/runs/42169660635/job/127734602256 ### Cause The dev server transforms modules on first request. The four pages this spec opens are 1,595 modules, and `mentions.html` alone is 1,589. Whichever page a worker opened first loaded them cold, and on a busy runner that took longer than the 15 s navigation timeout. #2776 describes the same cold load for `mentions.spec.mjs`, and lists this spec under "Remaining gaps". ### Fix - **Build:** `beforeAll` builds the four pages into a temp directory, and `preview` serves them on an OS-assigned port. `afterAll` closes the server and removes the directory. The config matches `voice-notes.spec.mjs` (#2566) and #2776. - **Dev checks kept:** the build defines `import.meta.env.DEV` and `process.env.NODE_ENV` as development, so StrictMode's checks still apply. - **Paths unchanged:** `test.use` points `baseURL` at the preview server, so every `page.goto` path stays the same. - **No conflict with #2776:** only this spec changes, so #2776 still merges cleanly. Once both land, the three copies of the build config could become one helper. ### Validation All runs were local on macOS (16 cores, load average 10–41) with the Playwright CI config. These are not hosted CI measurements. **Fail-before / pass-after.** A temporary `vite-server.mjs` probe (not committed) held the `globals.css` transform for 16 s, in both the dev server and the build: | | main | this branch | | --- | --- | --- | | `:28` (moves to `:83` on this branch) | ✘ `page.goto: Timeout 15000ms exceeded` (Chromium 15.1 s, WebKit 19.8 s) | ✓ 0.96 s Chromium, 0.97 s WebKit | | first `typeahead.html`, `emoji.html`, `messages.html` journeys | ✘ same error, 15.1 s each (Chromium) | ✓ 0.5–1.4 s | | whole file | n/a | 24/24, with the 16 s spent once in `beforeAll` | **Repeat run.** Chromium `--repeat-each=10 --workers=2`, two alternating runs each: | | result | wall time | user CPU | first test per worker | | --- | --- | --- | --- | --- | | main | 240/240 | 3.2 and 3.3 min | 839 s and 855 s | 4.2–4.8 s | | this branch | 240/240 | 2.0 and 1.9 min | 352 s and 339 s | 0.9 s | **Other checks:** - **Full file:** Chromium 24/24, WebKit 24/24. - **`scripts/flake-check.mjs select`:** I ran it for #2507's diff, a `MessageRow.tsx`-only change, `tests/fixtures/mentions.tsx` and `tests/fixtures/mentions.html`. Every selection matches main's, apart from the spec's 55-line shift. The spec still links to all four pages. - **Integration tests:** `tests/integration/flake-check.test.mjs` and `tests/integration/vite-fixture.test.mjs` pass 33/33. - **Biome:** clean. ### Browser coverage No browser cases are added or removed and no assertions change. Only how the fixture pages are served changes. ### Remaining gaps - **Other specs:** specs that load `mentions.html` from `source-fixture.mjs` or their own dev servers can still hit the same cold load. These include `channel-completion`, `completion-work`, `composer-*`, `mention-edit`, `mention-rules` and `mention-selection`. They are not changed here. - **Hosted CI:** it hasn't run on this branch yet, and a green run wouldn't show the flake is gone. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Matt Toohey <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 93a725d commit be67480

3 files changed

Lines changed: 70 additions & 44 deletions

File tree

‎tests/browser/typeahead.spec.mjs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
import { test, expect } from "./source-fixture.mjs";
1+
import { test, expect } from "./playwright-test.mjs";
2+
import { previewFixtures } from "./vite-server.mjs";
23
import { watchPageErrors } from "./page-errors.mjs";
34

5+
let fixtures;
6+
// A dev server serves these fixtures as about 1,600 modules, and a worker's
7+
// first navigation outlasted the navigation timeout on a busy runner.
8+
test.beforeAll(async () => {
9+
fixtures = await previewFixtures([
10+
"tests/fixtures/emoji.html",
11+
"tests/fixtures/mentions.html",
12+
"tests/fixtures/messages.html",
13+
"tests/fixtures/typeahead.html",
14+
]);
15+
});
16+
test.afterAll(() => fixtures?.close());
17+
// Journeys open the pages by path. The bundle's port is known only after
18+
// beforeAll, which runs before each test's fixtures. Playwright also resolves
19+
// baseURL for beforeAll itself, before the bundle exists.
20+
// biome-ignore lint/correctness/noEmptyPattern: Playwright requires a destructured fixture argument.
21+
test.use({ baseURL: async ({}, use) => use(fixtures?.origin) });
22+
423
const open = async (page) => {
524
await page.goto("/tests/fixtures/mentions.html?test-controls");
625
return page.getByRole("textbox", { name: "Message #General" });

‎tests/browser/vite-server.mjs‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,49 @@ export const preview = (config) =>
136136
}),
137137
);
138138

139+
// A dev server transforms a page's modules on first request, so a worker's
140+
// first navigation to a large fixture can outlast the navigation timeout on a
141+
// busy runner. This builds the repository-relative pages once and serves the
142+
// bundle. Development React, as a dev server serves, keeps StrictMode's checks.
143+
// close() stops the server and removes the build.
144+
export async function previewFixtures(pages) {
145+
const directory = await mkdtemp(join(tmpdir(), "buzz-fixture-preview-"));
146+
try {
147+
const config = {
148+
root,
149+
configFile: false,
150+
envDir: false,
151+
logLevel: "error",
152+
plugins: [react()],
153+
define: {
154+
"import.meta.env.DEV": "true",
155+
"process.env.NODE_ENV": '"development"',
156+
},
157+
build: {
158+
rollupOptions: { input: pages.map((page) => join(root, page)) },
159+
outDir: join(directory, "dist"),
160+
emptyOutDir: true,
161+
target: "esnext",
162+
},
163+
};
164+
await build(config);
165+
const server = await preview({
166+
...config,
167+
preview: { host: "127.0.0.1", port: 0, strictPort: true },
168+
});
169+
return {
170+
origin: `http://127.0.0.1:${server.httpServer.address().port}`,
171+
async close() {
172+
await new Promise((resolve) => server.httpServer.close(resolve));
173+
await rm(directory, { recursive: true, force: true });
174+
},
175+
};
176+
} catch (error) {
177+
await rm(directory, { recursive: true, force: true });
178+
throw error;
179+
}
180+
}
181+
139182
// Run once per test run, before any test: it scans and bundles the fixture
140183
// dependencies so no server does that work inside a navigation budget.
141184
export async function prepareFixtureDependencies() {

‎tests/browser/voice-notes.spec.mjs‎

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,13 @@
11
import { watchPageErrors } from "./page-errors.mjs";
22
import { test, expect } from "./playwright-test.mjs";
3-
import { build, preview } from "./vite-server.mjs";
4-
import react from "@vitejs/plugin-react";
5-
import { mkdtemp, rm } from "node:fs/promises";
6-
import { tmpdir } from "node:os";
7-
import { join } from "node:path";
8-
import { fileURLToPath } from "node:url";
9-
let server, directory, url;
10-
// A dev server serves this fixture as about 800 modules. On a busy runner,
11-
// WebKit's first navigation took longer than the navigation timeout to load
12-
// them, so build the page once and serve the bundle.
3+
import { previewFixtures } from "./vite-server.mjs";
4+
let fixtures;
5+
// A dev server serves this fixture as about 800 modules, and WebKit's first
6+
// navigation outlasted the navigation timeout on a busy runner.
137
test.beforeAll(async () => {
14-
const root = fileURLToPath(new URL("../../", import.meta.url));
15-
directory = await mkdtemp(join(tmpdir(), "buzz-voice-notes-"));
16-
const config = {
17-
root,
18-
configFile: false,
19-
envDir: false,
20-
logLevel: "error",
21-
plugins: [react()],
22-
// Development React, as the dev server served, keeps StrictMode's checks.
23-
define: {
24-
"import.meta.env.DEV": "true",
25-
"process.env.NODE_ENV": '"development"',
26-
},
27-
build: {
28-
rollupOptions: {
29-
input: join(root, "tests/fixtures/voice-notes.html"),
30-
},
31-
outDir: join(directory, "dist"),
32-
emptyOutDir: true,
33-
target: "esnext",
34-
},
35-
};
36-
await build(config);
37-
server = await preview({
38-
...config,
39-
preview: { host: "127.0.0.1", port: 0, strictPort: true },
40-
});
41-
url = `http://127.0.0.1:${server.httpServer.address().port}/tests/fixtures/voice-notes.html`;
42-
});
43-
test.afterAll(async () => {
44-
if (server) await new Promise((resolve) => server.httpServer.close(resolve));
45-
if (directory) await rm(directory, { recursive: true, force: true });
8+
fixtures = await previewFixtures(["tests/fixtures/voice-notes.html"]);
469
});
10+
test.afterAll(() => fixtures?.close());
4711
test.beforeEach(async ({ page }) => {
4812
await page.route("**/api/relay/media?*", async (route) => {
4913
const url = new URL(route.request().url()).searchParams.get("url");
@@ -59,7 +23,7 @@ test.beforeEach(async ({ page }) => {
5923
body: Buffer.from(bytes),
6024
});
6125
});
62-
await page.goto(url);
26+
await page.goto(`${fixtures.origin}/tests/fixtures/voice-notes.html`);
6327
await page.evaluate(() => {
6428
const mic = {
6529
mode: "allow",

0 commit comments

Comments
 (0)