test: dedupe and optimize test suites

This commit is contained in:
Peter Steinberger
2026-02-19 15:18:50 +00:00
parent b0e55283d5
commit a1cb700a05
80 changed files with 2627 additions and 2962 deletions

View File

@@ -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" });
});
});