





























@@ -67,6 +67,22 @@ async function runBrowserRequest(params: Record<string, unknown>) {
6767return { respond, nodeRegistry };
6868}
696970+function invokeParams(nodeRegistry: ReturnType<typeof createContext>) {
71+const call = (nodeRegistry.invoke.mock.calls as unknown[][])[0];
72+if (!call) {
73+throw new Error("expected browser node invoke call");
74+}
75+return call[0] as { command?: string; params?: Record<string, unknown> };
76+}
77+78+function firstRespondCall(respond: ReturnType<typeof vi.fn>): RespondCall {
79+const call = respond.mock.calls[0] as RespondCall | undefined;
80+if (!call) {
81+throw new Error("expected respond call");
82+}
83+return call;
84+}
85+7086describe("browser.request profile selection", () => {
7187beforeEach(() => {
7288loadConfigMock.mockReturnValue({
@@ -83,16 +99,10 @@ describe("browser.request profile selection", () => {
8399body: { profile: "work", request: { action: "click", ref: "btn1" } },
84100});
8510186-expect(nodeRegistry.invoke).toHaveBeenCalledWith(
87-expect.objectContaining({
88-command: "browser.proxy",
89-params: expect.objectContaining({
90-profile: "work",
91-}),
92-}),
93-);
94-const call = respond.mock.calls[0] as RespondCall | undefined;
95-expect(call?.[0]).toBe(true);
102+const invoke = invokeParams(nodeRegistry);
103+expect(invoke.command).toBe("browser.proxy");
104+expect(invoke.params?.profile).toBe("work");
105+expect(firstRespondCall(respond)[0]).toBe(true);
96106});
9710798108it("prefers query profile over body profile when both are present", async () => {
@@ -103,13 +113,7 @@ describe("browser.request profile selection", () => {
103113body: { profile: "work", request: { action: "click", ref: "btn1" } },
104114});
105115106-expect(nodeRegistry.invoke).toHaveBeenCalledWith(
107-expect.objectContaining({
108-params: expect.objectContaining({
109-profile: "chrome",
110-}),
111-}),
112-);
116+expect(invokeParams(nodeRegistry).params?.profile).toBe("chrome");
113117});
114118115119it.each([
@@ -151,13 +155,10 @@ describe("browser.request profile selection", () => {
151155});
152156153157expect(nodeRegistry.invoke).not.toHaveBeenCalled();
154-expect(respond).toHaveBeenCalledWith(
155-false,
156-undefined,
157-expect.objectContaining({
158-message: "browser.request cannot mutate persistent browser profiles",
159-}),
160-);
158+const [ok, payload, error] = firstRespondCall(respond);
159+expect(ok).toBe(false);
160+expect(payload).toBeUndefined();
161+expect(error?.message).toBe("browser.request cannot mutate persistent browser profiles");
161162});
162163163164it("allows non-mutating profile reads", async () => {
@@ -166,16 +167,10 @@ describe("browser.request profile selection", () => {
166167path: "/profiles",
167168});
168169169-expect(nodeRegistry.invoke).toHaveBeenCalledWith(
170-expect.objectContaining({
171-command: "browser.proxy",
172-params: expect.objectContaining({
173-method: "GET",
174-path: "/profiles",
175-}),
176-}),
177-);
178-const call = respond.mock.calls[0] as RespondCall | undefined;
179-expect(call?.[0]).toBe(true);
170+const invoke = invokeParams(nodeRegistry);
171+expect(invoke.command).toBe("browser.proxy");
172+expect(invoke.params?.method).toBe("GET");
173+expect(invoke.params?.path).toBe("/profiles");
174+expect(firstRespondCall(respond)[0]).toBe(true);
180175});
181176});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。