@@ -97,6 +97,10 @@ function expectDispatcherAttached(value: unknown): void {
|
97 | 97 | expect(getDispatcherClassName(value)).toMatch(/^(Agent|Mock)$/u); |
98 | 98 | } |
99 | 99 | |
| 100 | +function firstMockCall<T extends unknown[]>(mock: { mock: { calls: T[] } }): T | undefined { |
| 101 | +return mock.mock.calls[0]; |
| 102 | +} |
| 103 | + |
100 | 104 | function getSecondRequestHeaders(fetchImpl: ReturnType<typeof vi.fn>): Headers { |
101 | 105 | const [, secondInit] = fetchImpl.mock.calls.at(1) as [string, RequestInit]; |
102 | 106 | return new Headers(secondInit.headers); |
@@ -301,7 +305,7 @@ describe("fetchWithSsrFGuard hardening", () => {
|
301 | 305 | ).rejects.toThrow(/private|internal|blocked/i); |
302 | 306 | expect(fetchImpl).not.toHaveBeenCalled(); |
303 | 307 | expect(logWarnMock).toHaveBeenCalledTimes(1); |
304 | | -const [warning] = logWarnMock.mock.calls.at(0) as [string]; |
| 308 | +const [warning] = firstMockCall(logWarnMock) as [string]; |
305 | 309 | expect(warning).toContain( |
306 | 310 | "security: blocked URL fetch (qa-audit) targetOrigin=http://127.0.0.1:8080", |
307 | 311 | ); |
@@ -602,7 +606,7 @@ describe("fetchWithSsrFGuard hardening", () => {
|
602 | 606 | }, |
603 | 607 | }); |
604 | 608 | expect(fetchImpl).toHaveBeenCalledTimes(1); |
605 | | -const fetchCall = fetchImpl.mock.calls.at(0) as [string, { dispatcher?: unknown }] | undefined; |
| 609 | +const fetchCall = firstMockCall(fetchImpl) as [string, { dispatcher?: unknown }] | undefined; |
606 | 610 | expect(fetchCall?.[0]).toBe("https://public.example/resource"); |
607 | 611 | if (!fetchCall?.[1].dispatcher) { |
608 | 612 | throw new Error("Expected proxy dispatcher"); |
|