fix(qa): recover Playwright Chromium on Ubuntu 26

This commit is contained in:
Vincent Koc
2026-06-24 13:24:43 +08:00
parent 2ab3b223ed
commit fd66b44f5e
4 changed files with 194 additions and 6 deletions
@@ -2,7 +2,9 @@
import { describe, expect, it, vi } from "vitest";
import {
ensurePlaywrightChromium,
installLinuxSystemChromiumPackage,
resolvePlaywrightInstallRunner,
shouldEnsureFfmpegFromArgv,
shouldInstallPlaywrightSystemDependencies,
} from "../../scripts/ensure-playwright-chromium.mjs";
@@ -276,6 +278,55 @@ describe("ensurePlaywrightChromium", () => {
expect(logs.join("\n")).toContain("installing Linux system dependencies");
});
it("falls back to distro Chromium when Playwright does not support the Linux runner image", () => {
const logs: string[] = [];
let installedSystemChromium = false;
const spawnSync = vi.fn((command: string, args: string[]) => {
if (command === "pnpm" && args.includes("chromium")) {
return { status: 1 };
}
if (command === "apt-get" && args.includes("update")) {
return { status: 0 };
}
if (command === "apt-get" && args.includes("chromium-browser")) {
installedSystemChromium = true;
return { status: 0 };
}
if (command === "/usr/bin/chromium-browser") {
return { status: installedSystemChromium ? 0 : 127 };
}
return { status: 1 };
});
expect(
ensurePlaywrightChromium({
cwd: "/repo",
env: { CI: "1", PATH: "/bin" },
executablePath: "/cache/chromium/chrome",
existsSync: (path: string) =>
installedSystemChromium && path === "/usr/bin/chromium-browser",
getuid: () => 0,
log: (line: string) => logs.push(line),
platform: "linux",
spawnSync,
stdio: "pipe",
systemExecutablePath: "",
}),
).toBe(0);
expect(spawnSync).toHaveBeenCalledWith(
"apt-get",
["update", "-qq"],
expect.objectContaining({ cwd: "/repo", stdio: "pipe" }),
);
expect(spawnSync).toHaveBeenCalledWith(
"apt-get",
["install", "-y", "chromium-browser"],
expect.objectContaining({ cwd: "/repo", stdio: "pipe" }),
);
expect(logs.join("\n")).toContain("installing a system Chromium package");
expect(logs.join("\n")).toContain("Using system Chromium at /usr/bin/chromium-browser");
});
it("does not install Linux system dependencies for an unprivileged local lane", () => {
const spawnSync = vi
.fn()
@@ -343,6 +394,7 @@ describe("ensurePlaywrightChromium", () => {
ensurePlaywrightChromium({
executablePath: "/cache/chromium/chrome",
existsSync: () => false,
platform: "darwin",
spawnSync: vi.fn(() => ({ status: 23 })),
stdio: "pipe",
systemExecutablePath: "",
@@ -404,4 +456,45 @@ describe("ensurePlaywrightChromium", () => {
}),
).toBe(true);
});
it("installs Linux system Chromium packages with sudo for non-root lanes", () => {
const spawnSync = vi.fn(() => ({ status: 0 }));
expect(
installLinuxSystemChromiumPackage({
cwd: "/repo",
env: { PATH: "/bin" },
getuid: () => 501,
platform: "linux",
spawnSync,
stdio: "pipe",
}),
).toBe(0);
expect(spawnSync).toHaveBeenNthCalledWith(1, "sudo", ["-n", "true"], { stdio: "ignore" });
expect(spawnSync).toHaveBeenNthCalledWith(
2,
"sudo",
["-n", "apt-get", "update", "-qq"],
expect.objectContaining({ cwd: "/repo", stdio: "pipe" }),
);
expect(spawnSync).toHaveBeenNthCalledWith(
3,
"sudo",
["-n", "apt-get", "install", "-y", "chromium-browser"],
expect.objectContaining({ cwd: "/repo", stdio: "pipe" }),
);
});
it("allows QA scenario runners to skip optional Playwright ffmpeg", () => {
expect(shouldEnsureFfmpegFromArgv(["node", "scripts/ensure-playwright-chromium.mjs"])).toBe(
true,
);
expect(
shouldEnsureFfmpegFromArgv([
"node",
"scripts/ensure-playwright-chromium.mjs",
"--skip-ffmpeg",
]),
).toBe(false);
});
});