
























@@ -2,7 +2,9 @@
22import { describe, expect, it, vi } from "vitest";
33import {
44ensurePlaywrightChromium,
5+installLinuxSystemChromiumPackage,
56resolvePlaywrightInstallRunner,
7+shouldEnsureFfmpegFromArgv,
68shouldInstallPlaywrightSystemDependencies,
79} from "../../scripts/ensure-playwright-chromium.mjs";
810@@ -276,6 +278,55 @@ describe("ensurePlaywrightChromium", () => {
276278expect(logs.join("\n")).toContain("installing Linux system dependencies");
277279});
278280281+it("falls back to distro Chromium when Playwright does not support the Linux runner image", () => {
282+const logs: string[] = [];
283+let installedSystemChromium = false;
284+const spawnSync = vi.fn((command: string, args: string[]) => {
285+if (command === "pnpm" && args.includes("chromium")) {
286+return { status: 1 };
287+}
288+if (command === "apt-get" && args.includes("update")) {
289+return { status: 0 };
290+}
291+if (command === "apt-get" && args.includes("chromium-browser")) {
292+installedSystemChromium = true;
293+return { status: 0 };
294+}
295+if (command === "/usr/bin/chromium-browser") {
296+return { status: installedSystemChromium ? 0 : 127 };
297+}
298+return { status: 1 };
299+});
300+301+expect(
302+ensurePlaywrightChromium({
303+cwd: "/repo",
304+env: { CI: "1", PATH: "/bin" },
305+executablePath: "/cache/chromium/chrome",
306+existsSync: (path: string) =>
307+installedSystemChromium && path === "/usr/bin/chromium-browser",
308+getuid: () => 0,
309+log: (line: string) => logs.push(line),
310+platform: "linux",
311+ spawnSync,
312+stdio: "pipe",
313+systemExecutablePath: "",
314+}),
315+).toBe(0);
316+expect(spawnSync).toHaveBeenCalledWith(
317+"apt-get",
318+["update", "-qq"],
319+expect.objectContaining({ cwd: "/repo", stdio: "pipe" }),
320+);
321+expect(spawnSync).toHaveBeenCalledWith(
322+"apt-get",
323+["install", "-y", "chromium-browser"],
324+expect.objectContaining({ cwd: "/repo", stdio: "pipe" }),
325+);
326+expect(logs.join("\n")).toContain("installing a system Chromium package");
327+expect(logs.join("\n")).toContain("Using system Chromium at /usr/bin/chromium-browser");
328+});
329+279330it("does not install Linux system dependencies for an unprivileged local lane", () => {
280331const spawnSync = vi
281332.fn()
@@ -343,6 +394,7 @@ describe("ensurePlaywrightChromium", () => {
343394ensurePlaywrightChromium({
344395executablePath: "/cache/chromium/chrome",
345396existsSync: () => false,
397+platform: "darwin",
346398spawnSync: vi.fn(() => ({ status: 23 })),
347399stdio: "pipe",
348400systemExecutablePath: "",
@@ -404,4 +456,45 @@ describe("ensurePlaywrightChromium", () => {
404456}),
405457).toBe(true);
406458});
459+460+it("installs Linux system Chromium packages with sudo for non-root lanes", () => {
461+const spawnSync = vi.fn(() => ({ status: 0 }));
462+463+expect(
464+installLinuxSystemChromiumPackage({
465+cwd: "/repo",
466+env: { PATH: "/bin" },
467+getuid: () => 501,
468+platform: "linux",
469+ spawnSync,
470+stdio: "pipe",
471+}),
472+).toBe(0);
473+expect(spawnSync).toHaveBeenNthCalledWith(1, "sudo", ["-n", "true"], { stdio: "ignore" });
474+expect(spawnSync).toHaveBeenNthCalledWith(
475+2,
476+"sudo",
477+["-n", "apt-get", "update", "-qq"],
478+expect.objectContaining({ cwd: "/repo", stdio: "pipe" }),
479+);
480+expect(spawnSync).toHaveBeenNthCalledWith(
481+3,
482+"sudo",
483+["-n", "apt-get", "install", "-y", "chromium-browser"],
484+expect.objectContaining({ cwd: "/repo", stdio: "pipe" }),
485+);
486+});
487+488+it("allows QA scenario runners to skip optional Playwright ffmpeg", () => {
489+expect(shouldEnsureFfmpegFromArgv(["node", "scripts/ensure-playwright-chromium.mjs"])).toBe(
490+true,
491+);
492+expect(
493+shouldEnsureFfmpegFromArgv([
494+"node",
495+"scripts/ensure-playwright-chromium.mjs",
496+"--skip-ffmpeg",
497+]),
498+).toBe(false);
499+});
407500});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。