






















@@ -84,6 +84,24 @@ vi.mock("./net/http-connect-tunnel.js", () => ({
8484openHttpConnectTunnel: tunnelSpy,
8585}));
868687+function lastTunnelCall(): HttpConnectTunnelParams {
88+const calls = tunnelSpy.mock.calls;
89+const call = calls[calls.length - 1];
90+if (!call) {
91+throw new Error("expected HTTP CONNECT tunnel call");
92+}
93+return call[0];
94+}
95+96+function lastConnectCall(): [string, http2.ClientSessionOptions] {
97+const calls = connectSpy.mock.calls;
98+const call = calls[calls.length - 1];
99+if (!call) {
100+throw new Error("expected http2 connect call");
101+}
102+return call as unknown as [string, http2.ClientSessionOptions];
103+}
104+87105describe("connectApnsHttp2Session", () => {
88106beforeEach(() => {
89107connectSpy.mockClear();
@@ -153,22 +171,20 @@ describe("connectApnsHttp2Session", () => {
153171stopActiveManagedProxyRegistration(registration);
154172155173expect(session).toBe(fakeSession);
156-const tunnelCall = tunnelSpy.mock.calls.at(-1)?.[0];
157-const proxyUrl = tunnelCall?.proxyUrl;
174+const tunnelCall = lastTunnelCall();
175+const proxyUrl = tunnelCall.proxyUrl;
158176expect(proxyUrl).toBeInstanceOf(URL);
159177if (!(proxyUrl instanceof URL)) {
160178throw new Error("expected active managed proxy URL");
161179}
162180expect(proxyUrl.href).toBe("http://proxy.example:8080/");
163-expect(tunnelCall?.targetHost).toBe("api.push.apple.com");
164-expect(tunnelCall?.targetPort).toBe(443);
165-expect(tunnelCall?.timeoutMs).toBe(10_000);
181+expect(tunnelCall.targetHost).toBe("api.push.apple.com");
182+expect(tunnelCall.targetPort).toBe(443);
183+expect(tunnelCall.timeoutMs).toBe(10_000);
166184expect(connectSpy).toHaveBeenCalledTimes(1);
167-const connectCall = connectSpy.mock.calls.at(-1) as
168-| [string, http2.ClientSessionOptions]
169-| undefined;
170-expect(connectCall?.[0]).toBe("https://api.push.apple.com");
171-const createConnection = connectCall?.[1].createConnection;
185+const connectCall = lastConnectCall();
186+expect(connectCall[0]).toBe("https://api.push.apple.com");
187+const createConnection = connectCall[1].createConnection;
172188expect(typeof createConnection).toBe("function");
173189expect(createConnection?.(new URL("https://api.push.apple.com"), {})).toBe(fakeTlsSocket);
174190});
@@ -209,8 +225,8 @@ describe("connectApnsHttp2Session", () => {
209225body: '{"reason":"InvalidProviderToken"}',
210226responseHeaders: {},
211227});
212-const tunnelCall = tunnelSpy.mock.calls.at(-1)?.[0];
213-const proxyUrl = tunnelCall?.proxyUrl;
228+const tunnelCall = lastTunnelCall();
229+const proxyUrl = tunnelCall.proxyUrl;
214230expect(proxyUrl).toBeInstanceOf(URL);
215231if (!(proxyUrl instanceof URL)) {
216232throw new Error("expected explicit proxy URL");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。