mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: tighten browser route assertions
This commit is contained in:
@@ -144,7 +144,7 @@ describe("cdp internal", () => {
|
||||
return;
|
||||
}
|
||||
if (msg.method === "Page.captureScreenshot") {
|
||||
expect(msg.params).toMatchObject({ format: "png" });
|
||||
expect(msg.params?.format).toBe("png");
|
||||
expect(msg.params).not.toHaveProperty("captureBeyondViewport");
|
||||
socket.send(
|
||||
JSON.stringify({
|
||||
|
||||
@@ -49,6 +49,6 @@ describe("persistBrowserProxyFiles", () => {
|
||||
|
||||
await expect(
|
||||
fs.stat(path.join(tempHome.home, ".openclaw", "media", "browser")),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
).rejects.toHaveProperty("code", "ENOENT");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -249,14 +249,13 @@ describe("pw-session ensurePageState", () => {
|
||||
handlers.get("pageerror")?.[0]?.(new Error("boom"));
|
||||
|
||||
expect(state.errors.at(-1)?.message).toBe("boom");
|
||||
expect(state.requests.at(-1)).toMatchObject({
|
||||
method: "GET",
|
||||
url: "https://example.com/api",
|
||||
resourceType: "xhr",
|
||||
status: 500,
|
||||
ok: false,
|
||||
failureText: "net::ERR_FAILED",
|
||||
});
|
||||
const request = state.requests.at(-1);
|
||||
expect(request?.method).toBe("GET");
|
||||
expect(request?.url).toBe("https://example.com/api");
|
||||
expect(request?.resourceType).toBe("xhr");
|
||||
expect(request?.status).toBe(500);
|
||||
expect(request?.ok).toBe(false);
|
||||
expect(request?.failureText).toBe("net::ERR_FAILED");
|
||||
});
|
||||
|
||||
it("drops state on page close", () => {
|
||||
|
||||
@@ -56,13 +56,10 @@ describe("batchViaPlaywright", () => {
|
||||
});
|
||||
|
||||
expect(result).toEqual({ results: [{ ok: true }] });
|
||||
expect(page?.evaluate).toHaveBeenCalledWith(
|
||||
expect.any(Function),
|
||||
expect.objectContaining({
|
||||
fnBody: "() => 1",
|
||||
timeoutMs: 4500,
|
||||
}),
|
||||
);
|
||||
const [evaluateFn, evaluateOptions] = page?.evaluate.mock.calls[0] ?? [];
|
||||
expect(evaluateFn).toEqual(expect.any(Function));
|
||||
expect(evaluateOptions?.fnBody).toBe("() => 1");
|
||||
expect(evaluateOptions?.timeoutMs).toBe(4500);
|
||||
});
|
||||
|
||||
it("supports resize and close inside a batch", async () => {
|
||||
|
||||
@@ -118,10 +118,9 @@ describe("existing-session interaction navigation guard", () => {
|
||||
urls.length,
|
||||
);
|
||||
for (const [index, url] of urls.entries()) {
|
||||
expect(navigationGuardMocks.assertBrowserNavigationResultAllowed).toHaveBeenNthCalledWith(
|
||||
index + 1,
|
||||
expect.objectContaining({ url }),
|
||||
);
|
||||
expect(
|
||||
navigationGuardMocks.assertBrowserNavigationResultAllowed.mock.calls[index]?.[0]?.url,
|
||||
).toBe(url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,9 +136,10 @@ describe("existing-session interaction navigation guard", () => {
|
||||
expect(clickResponse.statusCode).toBe(200);
|
||||
expect(typeResponse.statusCode).toBe(200);
|
||||
expect(chromeMcpMocks.clickChromeMcpElement).toHaveBeenCalledOnce();
|
||||
expect(chromeMcpMocks.pressChromeMcpKey).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ key: "Enter" }),
|
||||
);
|
||||
const keyPressCalls = chromeMcpMocks.pressChromeMcpKey.mock.calls as unknown as Array<
|
||||
[{ key?: string }]
|
||||
>;
|
||||
expect(keyPressCalls[0]?.[0]?.key).toBe("Enter");
|
||||
expectNavigationProbeUrls(Array.from({ length: 6 }, () => "https://example.com"));
|
||||
});
|
||||
|
||||
|
||||
@@ -329,10 +329,15 @@ describe("basic browser routes", () => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(isTransportAvailable).toHaveBeenCalledTimes(1);
|
||||
expect(isTransportAvailable).toHaveBeenCalledWith(5_000);
|
||||
expect(isReachable).toHaveBeenCalledWith(
|
||||
expect.any(Number),
|
||||
expect.objectContaining({ ephemeral: true, signal: expect.any(AbortSignal) }),
|
||||
);
|
||||
const [timeoutMs, reachabilityOptions] =
|
||||
(
|
||||
isReachable.mock.calls as unknown as Array<
|
||||
[number, { ephemeral?: boolean; signal?: AbortSignal }]
|
||||
>
|
||||
)[0] ?? [];
|
||||
expect(timeoutMs).toEqual(expect.any(Number));
|
||||
expect(reachabilityOptions?.ephemeral).toBe(true);
|
||||
expect(reachabilityOptions?.signal).toBeInstanceOf(AbortSignal);
|
||||
expect(isHttpReachable).not.toHaveBeenCalled();
|
||||
const body = responseBodyRecord(response);
|
||||
expect(body.cdpHttp).toBe(true);
|
||||
@@ -357,10 +362,15 @@ describe("basic browser routes", () => {
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(isReachable).toHaveBeenCalledWith(
|
||||
4_000,
|
||||
expect.objectContaining({ ephemeral: true, signal: expect.any(AbortSignal) }),
|
||||
);
|
||||
const [timeoutMs, reachabilityOptions] =
|
||||
(
|
||||
isReachable.mock.calls as unknown as Array<
|
||||
[number, { ephemeral?: boolean; signal?: AbortSignal }]
|
||||
>
|
||||
)[0] ?? [];
|
||||
expect(timeoutMs).toBe(4_000);
|
||||
expect(reachabilityOptions?.ephemeral).toBe(true);
|
||||
expect(reachabilityOptions?.signal).toBeInstanceOf(AbortSignal);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
@@ -382,9 +392,8 @@ describe("basic browser routes", () => {
|
||||
});
|
||||
|
||||
expect(isReachable).toHaveBeenCalledTimes(1);
|
||||
expect(isReachable.mock.calls[0]?.[1]).toEqual(
|
||||
expect.objectContaining({ ephemeral: true, signal: expect.any(AbortSignal) }),
|
||||
);
|
||||
expect(isReachable.mock.calls[0]?.[1]?.ephemeral).toBe(true);
|
||||
expect(isReachable.mock.calls[0]?.[1]?.signal).toBeInstanceOf(AbortSignal);
|
||||
});
|
||||
|
||||
it("skips the page-reachability probe when transport is unavailable", async () => {
|
||||
|
||||
Reference in New Issue
Block a user