Skip to content

Commit 3720e4b

Browse files
NERLOEclaude
andcommitted
fix(build): test the dry-run header pattern directly
Lift the pattern into dryRunHeaderPattern() so the test exercises it without a hand-built BuildContext. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent b9dd0f0 commit 3720e4b

2 files changed

Lines changed: 20 additions & 45 deletions

File tree

packages/build/src/extensions/playwright.test.ts

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, it } from "vitest";
2-
import type { BuildContext, BuildLayer } from "@trigger.dev/core/v3/build";
3-
import { playwright } from "./playwright.js";
2+
import { dryRunHeaderPattern } from "./playwright.js";
43

54
// Real `playwright install --dry-run` headers, before and after the 1.58 format change.
65
const HEADERS = {
@@ -19,52 +18,18 @@ const HEADERS = {
1918
},
2019
} as const;
2120

22-
type BrowserKey = keyof (typeof HEADERS)["1.57"];
23-
24-
function generatedInstructions(options: Parameters<typeof playwright>[0]): string[] {
25-
let captured: BuildLayer | undefined;
26-
27-
const context = {
28-
target: "deploy",
29-
logger: { debug: () => {} },
30-
addLayer: (layer: BuildLayer) => {
31-
captured = layer;
32-
},
33-
} as unknown as BuildContext;
34-
35-
const manifest = {
36-
externals: [{ name: "playwright", version: "1.62.0" }],
37-
} as any;
38-
39-
playwright(options).onBuildComplete!(context, manifest);
40-
41-
return captured?.image?.instructions ?? [];
42-
}
43-
44-
/** The ERE the generated `grep -E "<pattern>"` step selects a browser's block with. */
45-
function headerPattern(instructions: string[], browser: BrowserKey): RegExp {
46-
const step = instructions.find((line) => line.endsWith(`> /tmp/${browser}-info.txt`));
47-
const match = step?.match(/grep [^"]*"(.+)" \/tmp\/browser-info\.txt/);
48-
if (!match?.[1]) throw new Error(`no header grep generated for ${browser}`);
49-
return new RegExp(match[1]);
50-
}
51-
52-
describe("playwright extension dry-run header parsing", () => {
53-
const instructions = generatedInstructions({
54-
browsers: ["chromium", "firefox", "webkit"],
55-
headless: false,
56-
});
57-
const browsers = Object.keys(HEADERS["1.57"]) as BrowserKey[];
21+
const browsers = Object.keys(HEADERS["1.57"]) as Array<keyof (typeof HEADERS)["1.57"]>;
5822

23+
describe("playwright extension dry-run header pattern", () => {
5924
it.each(browsers)("selects the %s block in both output formats", (browser) => {
60-
const pattern = headerPattern(instructions, browser);
25+
const pattern = new RegExp(dryRunHeaderPattern(browser));
6126

6227
expect(pattern.test(HEADERS["1.57"][browser])).toBe(true);
6328
expect(pattern.test(HEADERS["1.62"][browser])).toBe(true);
6429
});
6530

6631
it.each(browsers)("does not select another browser's block for %s", (browser) => {
67-
const pattern = headerPattern(instructions, browser);
32+
const pattern = new RegExp(dryRunHeaderPattern(browser));
6833

6934
for (const other of browsers.filter((b) => b !== browser)) {
7035
expect(pattern.test(HEADERS["1.57"][other])).toBe(false);

packages/build/src/extensions/playwright.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ export function playwright(options: PlaywrightExtensionOptions = {}) {
196196
return new PlaywrightExtension(options);
197197
}
198198

199+
/**
200+
* Extended regex selecting a browser's block header in `playwright install --dry-run` output.
201+
*
202+
* Playwright < 1.58 prints `browser: <name> version <v>`; 1.58+ prints
203+
* `<Product> <v> (playwright <name> v<build>)`. The trailing space / `v` keep
204+
* `chromium` from matching the `chromium-headless-shell` block.
205+
*
206+
* @internal
207+
*/
208+
export function dryRunHeaderPattern(browser: string): string {
209+
return `browser: ${browser} |\\(playwright ${browser} v`;
210+
}
211+
199212
/**
200213
* Background:
201214
*
@@ -317,12 +330,9 @@ class PlaywrightExtension implements BuildExtension {
317330

318331
Array.from(browsersToInstall).forEach((browser) => {
319332
instructions.push(
320-
// Playwright < 1.58 prints `browser: <name> version <v>`; 1.58+ prints
321-
// `<Product> <v> (playwright <name> v<build>)`. The trailing space / `v`
322-
// keep `chromium` from matching the `chromium-headless-shell` block, and
323-
// only the two lines after the header (install location, download url)
333+
// Only the two lines after the header (install location, download url)
324334
// are read, so the window stops there.
325-
`RUN grep -A2 -m1 -E "browser: ${browser} |\\(playwright ${browser} v" /tmp/browser-info.txt > /tmp/${browser}-info.txt`,
335+
`RUN grep -A2 -m1 -E "${dryRunHeaderPattern(browser)}" /tmp/browser-info.txt > /tmp/${browser}-info.txt`,
326336

327337
`RUN INSTALL_DIR=$(grep "Install location:" /tmp/${browser}-info.txt | cut -d':' -f2- | xargs) && \
328338
DIR_NAME=$(basename "$INSTALL_DIR") && \

0 commit comments

Comments
 (0)