import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { loadCiGateContract, PLAYWRIGHT_JOB_IMAGE_PATTERN } from "../../scripts/contracts/ci-gates.ts"; import { renderCiWorkflow } from "../../scripts/generate-ci-workflow.ts"; /** * merge_browser runs in Playwright's own image so it does not download the * browsers and their OS libraries in every job (about 900 MB, 200 to 240 s on * the runner). The image's browsers are the ones @playwright/test of the same * version expects; a Playwright update without the image left the browsers * missing (or the image without the version's revisions). */ describe("browser job image", () => { it("is Playwright's image for the pinned @playwright/test version, by digest", async () => { const pinned = ( JSON.parse(readFileSync("package.json", "utf8")) as { devDependencies: Record } ).devDependencies["@playwright/test"]; const contract = await loadCiGateContract(process.cwd()); const images = contract.jobs.flatMap((job) => job.steps.flatMap((step) => (step.kind === "browser-install" && step.image ? [[job.id, step.image] as const] : [])), ); expect(images.map(([jobId]) => jobId)).toEqual(["merge_browser"]); for (const [, image] of images) { expect(PLAYWRIGHT_JOB_IMAGE_PATTERN.exec(image)?.[1]).toBe(pinned); } }); it("is the job container, and the runner image the build records", async () => { const contract = await loadCiGateContract(process.cwd()); const image = contract.jobs .find(({ id }) => id === "merge_browser")! .steps.find((step) => step.kind === "browser-install"); const workflow = renderCiWorkflow(contract); const job = workflow.slice(workflow.indexOf(" merge_browser:\n"), workflow.indexOf(" release_gate:\n")); expect(image?.kind === "browser-install" && image.image).toBeTruthy(); const ref = image?.kind === "browser-install" ? image.image! : ""; expect(job).toContain(` container:\n image: "${ref}"\n`); expect(job).toContain(` env:\n CI_RUNNER_IMAGE: "${ref}"\n`); expect(job).not.toContain("playwright install"); }); it("refuses an image outside Playwright's registry or without a digest", async () => { for (const image of [ "mcr.microsoft.com/playwright:v1.62.0-noble", "docker.io/library/ubuntu:24.04@sha256:" + "a".repeat(64), ]) { expect(PLAYWRIGHT_JOB_IMAGE_PATTERN.test(image), image).toBe(false); } }); });