chore: Fix types in tests 45/N.

This commit is contained in:
cpojer
2026-02-17 15:49:07 +09:00
parent 52ad28e097
commit 048e29ea35
13 changed files with 67 additions and 27 deletions

View File

@@ -1,11 +1,12 @@
import { afterEach, describe, expect, it } from "vitest";
import { startBrowserBridgeServer, stopBrowserBridgeServer } from "./bridge-server.js";
import type { ResolvedBrowserConfig } from "./config.js";
import {
DEFAULT_OPENCLAW_BROWSER_COLOR,
DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME,
} from "./constants.js";
function buildResolvedConfig() {
function buildResolvedConfig(): ResolvedBrowserConfig {
return {
enabled: true,
evaluateEnabled: false,
@@ -15,6 +16,7 @@ function buildResolvedConfig() {
cdpIsLoopback: true,
remoteCdpTimeoutMs: 1500,
remoteCdpHandshakeTimeoutMs: 3000,
extraArgs: [],
color: DEFAULT_OPENCLAW_BROWSER_COLOR,
executablePath: undefined,
headless: true,
@@ -27,7 +29,7 @@ function buildResolvedConfig() {
color: DEFAULT_OPENCLAW_BROWSER_COLOR,
},
},
} as const;
} as unknown as ResolvedBrowserConfig;
}
describe("startBrowserBridgeServer auth", () => {

View File

@@ -33,6 +33,9 @@ describe("cdp", () => {
it("creates a target via the browser websocket", async () => {
const wsPort = await startWsServer();
if (!wsServer) {
throw new Error("ws server not initialized");
}
wsServer.on("connection", (socket) => {
socket.on("message", (data) => {
@@ -80,6 +83,9 @@ describe("cdp", () => {
it("evaluates javascript via CDP", async () => {
const wsPort = await startWsServer();
if (!wsServer) {
throw new Error("ws server not initialized");
}
wsServer.on("connection", (socket) => {
socket.on("message", (data) => {
@@ -115,6 +121,9 @@ describe("cdp", () => {
it("captures an aria snapshot via CDP", async () => {
const wsPort = await startWsServer();
if (!wsServer) {
throw new Error("ws server not initialized");
}
wsServer.on("connection", (socket) => {
socket.on("message", (data) => {

View File

@@ -153,7 +153,9 @@ describe("port collision prevention", () => {
const { resolveBrowserConfig } = await import("./config.js");
// Simulate what happens with raw config (empty) vs resolved config
const rawConfig = { browser: {} }; // Fresh config, no profiles
const rawConfig: { browser: { profiles?: Record<string, { cdpPort?: number }> } } = {
browser: {},
}; // Fresh config, no profiles
const buggyUsedPorts = getUsedPorts(rawConfig.browser?.profiles);
const buggyAllocatedPort = allocateCdpPort(buggyUsedPorts);
@@ -161,7 +163,9 @@ describe("port collision prevention", () => {
expect(buggyAllocatedPort).toBe(CDP_PORT_RANGE_START);
// Resolved config: includes implicit openclaw at 18800
const resolved = resolveBrowserConfig(rawConfig.browser);
const resolved = resolveBrowserConfig(
rawConfig.browser as Parameters<typeof resolveBrowserConfig>[0],
);
const fixedUsedPorts = getUsedPorts(resolved.profiles);
const fixedAllocatedPort = allocateCdpPort(fixedUsedPorts);

View File

@@ -51,7 +51,7 @@ function createBrowser(pages: unknown[]) {
contexts: () => [ctx],
on: vi.fn(),
close: vi.fn().mockResolvedValue(undefined),
};
} as unknown as import("playwright-core").Browser;
}
let chromiumMock: typeof import("playwright-core").chromium;

View File

@@ -44,8 +44,11 @@ describe("pw-tools-core", () => {
paths: ["/tmp/2"],
});
resolve1?.(fc1);
resolve2?.(fc2);
if (!resolve1 || !resolve2) {
throw new Error("file chooser handlers were not registered");
}
(resolve1 as (value: unknown) => void)(fc1);
(resolve2 as (value: unknown) => void)(fc2);
await Promise.resolve();
expect(fc1.setFiles).not.toHaveBeenCalled();

View File

@@ -14,6 +14,10 @@ function makeBrowserState(): BrowserServerState {
cdpProtocol: "http",
cdpHost: "127.0.0.1",
cdpIsLoopback: true,
evaluateEnabled: false,
remoteCdpTimeoutMs: 1500,
remoteCdpHandshakeTimeoutMs: 3000,
extraArgs: [],
color: "#FF4500",
headless: true,
noSandbox: false,