























11// Qa Lab tests cover web runtime plugin behavior.
22import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
3-import { beforeEach, describe, expect, it, vi } from "vitest";
3+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4455const {
66 bodyLocator,
77 browserClose,
88 contextClose,
99 contextNewPage,
10+ existsSync,
1011 goto,
1112 launch,
1213 locatorFill,
@@ -17,6 +18,7 @@ const {
1718 pageUrl,
1819 pageWaitForFunction,
1920 pageWaitForSelector,
21+ spawnSync,
2022} = vi.hoisted(() => ({
2123bodyLocator: {
2224waitFor: vi.fn(async () => undefined),
@@ -25,6 +27,7 @@ const {
2527browserClose: vi.fn(async () => undefined),
2628contextClose: vi.fn(async () => undefined),
2729contextNewPage: vi.fn(),
30+existsSync: vi.fn((_candidate: unknown) => false),
2831goto: vi.fn(async () => undefined),
2932launch: vi.fn(),
3033locatorFill: vi.fn(async () => undefined),
@@ -35,6 +38,16 @@ const {
3538pageUrl: vi.fn(() => "http://127.0.0.1:3000/chat"),
3639pageWaitForFunction: vi.fn(async () => undefined),
3740pageWaitForSelector: vi.fn(async () => undefined),
41+spawnSync: vi.fn(() => ({ status: 0 })),
42+}));
43+44+vi.mock("node:child_process", () => ({
45+ spawnSync,
46+}));
47+48+vi.mock("node:fs", async (importOriginal) => ({
49+ ...(await importOriginal<typeof import("node:fs")>()),
50+ existsSync,
3851}));
39524053vi.mock("playwright-core", () => ({
@@ -85,6 +98,12 @@ beforeEach(async () => {
8598contextNewPage.mockResolvedValue(page);
8699launch.mockResolvedValue(browser);
87100vi.clearAllMocks();
101+existsSync.mockReturnValue(false);
102+spawnSync.mockReturnValue({ status: 0 });
103+});
104+105+afterEach(() => {
106+vi.unstubAllEnvs();
88107});
8910890109function requireLaunchOptions() {
@@ -116,7 +135,13 @@ describe("qa web runtime", () => {
116135await closeQaWebSessions();
117136118137const launchOptions = requireLaunchOptions();
119-expect(launchOptions?.channel).toBe("chrome");
138+expect(spawnSync).toHaveBeenCalledWith(
139+process.execPath,
140+["scripts/ensure-playwright-chromium.mjs", "--skip-ffmpeg"],
141+expect.objectContaining({ cwd: process.cwd(), stdio: "inherit" }),
142+);
143+expect(launchOptions?.channel).toBeUndefined();
144+expect(launchOptions?.executablePath).toBeUndefined();
120145expect(launchOptions?.headless).toBe(true);
121146expect(goto).toHaveBeenCalledWith("http://127.0.0.1:3000/chat", {
122147waitUntil: "domcontentloaded",
@@ -132,6 +157,44 @@ describe("qa web runtime", () => {
132157expect(browserClose).toHaveBeenCalledTimes(1);
133158});
134159160+it("launches an explicit Chromium executable override when configured", async () => {
161+vi.stubEnv("PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH", "/custom/chromium");
162+existsSync.mockImplementation((candidate) => candidate === "/custom/chromium");
163+164+await qaWebOpenPage({ url: "http://127.0.0.1:3000/chat" });
165+166+const launchOptions = requireLaunchOptions();
167+expect(spawnSync).toHaveBeenCalledWith("/custom/chromium", ["--version"], {
168+stdio: "ignore",
169+});
170+expect(launchOptions?.channel).toBeUndefined();
171+expect(launchOptions?.executablePath).toBe("/custom/chromium");
172+await closeQaWebSessions();
173+});
174+175+it("launches detected system Chromium without requiring branded Chrome", async () => {
176+existsSync.mockImplementation((candidate) => candidate === "/usr/bin/chromium");
177+178+await qaWebOpenPage({ url: "http://127.0.0.1:3000/chat" });
179+180+const launchOptions = requireLaunchOptions();
181+expect(spawnSync).toHaveBeenCalledWith("/usr/bin/chromium", ["--version"], {
182+stdio: "ignore",
183+});
184+expect(launchOptions?.channel).toBeUndefined();
185+expect(launchOptions?.executablePath).toBe("/usr/bin/chromium");
186+await closeQaWebSessions();
187+});
188+189+it("keeps an explicit browser channel request explicit", async () => {
190+await qaWebOpenPage({ url: "http://127.0.0.1:3000/chat", channel: "chrome" });
191+192+const launchOptions = requireLaunchOptions();
193+expect(launchOptions?.channel).toBe("chrome");
194+expect(launchOptions?.executablePath).toBeUndefined();
195+await closeQaWebSessions();
196+});
197+135198it("can close only selected page sessions", async () => {
136199const first = await qaWebOpenPage({ url: "http://127.0.0.1:3000/one" });
137200const second = await qaWebOpenPage({ url: "http://127.0.0.1:3000/two" });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。