mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 15:51:22 +00:00
test: dedupe and optimize test suites
This commit is contained in:
@@ -46,6 +46,12 @@ describe("browser state option collisions", () => {
|
||||
return call[1] as { body?: Record<string, unknown> };
|
||||
};
|
||||
|
||||
const runBrowserCommand = async (argv: string[]) => {
|
||||
const program = createBrowserProgram();
|
||||
await program.parseAsync(["browser", ...argv], { from: "user" });
|
||||
return getLastRequest();
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.callBrowserRequest.mockClear();
|
||||
mocks.runBrowserResizeWithOutput.mockClear();
|
||||
@@ -55,35 +61,24 @@ describe("browser state option collisions", () => {
|
||||
});
|
||||
|
||||
it("forwards parent-captured --target-id on `browser cookies set`", async () => {
|
||||
const program = createBrowserProgram();
|
||||
const request = await runBrowserCommand([
|
||||
"cookies",
|
||||
"set",
|
||||
"session",
|
||||
"abc",
|
||||
"--url",
|
||||
"https://example.com",
|
||||
"--target-id",
|
||||
"tab-1",
|
||||
]);
|
||||
|
||||
await program.parseAsync(
|
||||
[
|
||||
"browser",
|
||||
"cookies",
|
||||
"set",
|
||||
"session",
|
||||
"abc",
|
||||
"--url",
|
||||
"https://example.com",
|
||||
"--target-id",
|
||||
"tab-1",
|
||||
],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const request = getLastRequest() as { body?: { targetId?: string } };
|
||||
expect(request.body?.targetId).toBe("tab-1");
|
||||
expect((request as { body?: { targetId?: string } }).body?.targetId).toBe("tab-1");
|
||||
});
|
||||
|
||||
it("accepts legacy parent `--json` by parsing payload via positional headers fallback", async () => {
|
||||
const program = createBrowserProgram();
|
||||
|
||||
await program.parseAsync(["browser", "set", "headers", "--json", '{"x-auth":"ok"}'], {
|
||||
from: "user",
|
||||
});
|
||||
|
||||
const request = getLastRequest() as { body?: { headers?: Record<string, string> } };
|
||||
const request = (await runBrowserCommand(["set", "headers", "--json", '{"x-auth":"ok"}'])) as {
|
||||
body?: { headers?: Record<string, string> };
|
||||
};
|
||||
expect(request.body?.headers).toEqual({ "x-auth": "ok" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user