mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:40:44 +00:00
test(browser): avoid real retry waits
This commit is contained in:
@@ -246,6 +246,18 @@ describe("cdp", () => {
|
||||
const msg = JSON.parse(rawDataToString(data)) as { id?: number; method?: string };
|
||||
if (msg.method === "Target.createTarget") {
|
||||
socket.send(JSON.stringify({ id: msg.id, result: { targetId: "T_QP" } }));
|
||||
} else if (msg.method === "Target.attachToTarget") {
|
||||
socket.send(JSON.stringify({ id: msg.id, result: { sessionId: "S1" } }));
|
||||
} else if (
|
||||
msg.method === "Target.detachFromTarget" ||
|
||||
msg.method === "Page.enable" ||
|
||||
msg.method === "Runtime.enable" ||
|
||||
msg.method === "Network.enable" ||
|
||||
msg.method === "DOM.enable" ||
|
||||
msg.method === "Accessibility.enable" ||
|
||||
msg.method === "Runtime.runIfWaitingForDebugger"
|
||||
) {
|
||||
socket.send(JSON.stringify({ id: msg.id, result: {} }));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -461,20 +473,25 @@ describe("cdp", () => {
|
||||
});
|
||||
const wss = new WebSocketServer({ noServer: true });
|
||||
server.on("upgrade", (req, socket, head) => {
|
||||
if (req.url?.startsWith("/e/bad")) {
|
||||
socket.destroy();
|
||||
return;
|
||||
}
|
||||
wss.handleUpgrade(req, socket, head, (ws) => {
|
||||
wss.emit("connection", ws, req);
|
||||
});
|
||||
});
|
||||
wss.on("connection", (socket) => {
|
||||
wss.on("connection", (socket, req) => {
|
||||
socket.on("message", (data) => {
|
||||
const msg = JSON.parse(rawDataToString(data)) as {
|
||||
id?: number;
|
||||
method?: string;
|
||||
};
|
||||
if (req.url?.startsWith("/e/bad")) {
|
||||
socket.send(
|
||||
JSON.stringify({
|
||||
id: msg.id,
|
||||
error: { message: "Browserless endpoint rejected command" },
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (msg.method === "Target.createTarget") {
|
||||
socket.send(JSON.stringify({ id: msg.id, result: { targetId: "ROOT_FALLBACK" } }));
|
||||
} else if (msg.method === "Target.attachToTarget") {
|
||||
|
||||
@@ -369,13 +369,14 @@ describe("chrome.ts internal", () => {
|
||||
cdpIsLoopback: true,
|
||||
}) as unknown as ResolvedBrowserProfile;
|
||||
|
||||
const makeResolved = (): ResolvedBrowserConfig =>
|
||||
const makeResolved = (overrides: Partial<ResolvedBrowserConfig> = {}): ResolvedBrowserConfig =>
|
||||
({
|
||||
headless: true,
|
||||
noSandbox: true,
|
||||
extraArgs: [],
|
||||
localLaunchTimeoutMs: 15_000,
|
||||
localCdpReadyTimeoutMs: 8_000,
|
||||
...overrides,
|
||||
}) as unknown as ResolvedBrowserConfig;
|
||||
|
||||
it("rejects a remote profile before attempting to spawn", async () => {
|
||||
@@ -528,7 +529,10 @@ describe("chrome.ts internal", () => {
|
||||
await fsp.symlink("remote-host-535", path.join(userDataDir, "SingletonLock"));
|
||||
|
||||
try {
|
||||
const running = await launchOpenClawChrome(makeResolved(), profile);
|
||||
const running = await launchOpenClawChrome(
|
||||
makeResolved({ localLaunchTimeoutMs: 20 }),
|
||||
profile,
|
||||
);
|
||||
expect(running.proc).toBe(secondProc);
|
||||
expect(firstProc.kill).toHaveBeenCalledWith("SIGKILL");
|
||||
expect(spawnCalls).toBe(2);
|
||||
|
||||
Reference in New Issue
Block a user