





















@@ -278,8 +278,9 @@ describe("createDiscordGatewayPlugin", () => {
278278expect((plugin as unknown as { gatewayInfo?: { url?: string } }).gatewayInfo?.url).toBe(
279279"wss://gateway.discord.gg/",
280280);
281-expect(runtime.log).toHaveBeenCalledWith(
282-expect.stringContaining("discord: gateway metadata lookup failed transiently"),
281+expect(runtime.log).toHaveBeenCalledTimes(1);
282+expect(String(runtime.log.mock.calls[0]?.[0])).toContain(
283+"discord: gateway metadata lookup failed transiently",
283284);
284285}
285286@@ -326,12 +327,13 @@ describe("createDiscordGatewayPlugin", () => {
326327327328await registerGatewayClientWithMetadata({ plugin, fetchMock: globalFetchMock });
328329329-expect(globalFetchMock).toHaveBeenCalledWith(
330-"https://discord.com/api/v10/gateway/bot",
331-expect.objectContaining({
332-headers: { Authorization: "Bot token-123" },
333-}),
334-);
330+expect(globalFetchMock).toHaveBeenCalledTimes(1);
331+const fetchInit = globalFetchMock.mock.calls[0]?.[1] as
332+| { headers?: Record<string, string>; signal?: unknown }
333+| undefined;
334+expect(globalFetchMock.mock.calls[0]?.[0]).toBe("https://discord.com/api/v10/gateway/bot");
335+expect(fetchInit?.headers).toEqual({ Authorization: "Bot token-123" });
336+expect(fetchInit?.signal).toBeInstanceOf(AbortSignal);
335337expect(baseRegisterClientSpy).toHaveBeenCalledTimes(1);
336338});
337339@@ -346,16 +348,14 @@ describe("createDiscordGatewayPlugin", () => {
346348.createWebSocket;
347349createWebSocket("wss://gateway.discord.gg");
348350349-expect(httpsAgentSpy).toHaveBeenCalledWith(
350-expect.objectContaining({ lookup: expect.any(Function) }),
351-);
352-expect(webSocketSpy).toHaveBeenCalledWith(
353-"wss://gateway.discord.gg",
354-expect.objectContaining({
355-agent: getLastAgent(),
356-handshakeTimeout: 30_000,
357-}),
358-);
351+expect(httpsAgentSpy).toHaveBeenCalledTimes(1);
352+const httpsAgentOptions = httpsAgentSpy.mock.calls[0]?.[0] as { lookup?: unknown } | undefined;
353+expect(Object.keys(httpsAgentOptions ?? {})).toEqual(["lookup"]);
354+expect(typeof httpsAgentOptions?.lookup).toBe("function");
355+expect(webSocketSpy).toHaveBeenCalledWith("wss://gateway.discord.gg", {
356+agent: getLastAgent(),
357+handshakeTimeout: 30_000,
358+});
359359expect(wsProxyAgentSpy).not.toHaveBeenCalled();
360360});
361361@@ -467,10 +467,10 @@ describe("createDiscordGatewayPlugin", () => {
467467createWebSocket("wss://gateway.discord.gg");
468468469469expect(wsProxyAgentSpy).toHaveBeenCalledWith("http://127.0.0.1:8080");
470-expect(webSocketSpy).toHaveBeenCalledWith(
471-"wss://gateway.discord.gg",
472-expect.objectContaining({ agent: getLastProxyAgent(), handshakeTimeout: 30_000 }),
473-);
470+expect(webSocketSpy).toHaveBeenCalledWith("wss://gateway.discord.gg", {
471+agent: getLastProxyAgent(),
472+handshakeTimeout: 30_000,
473+});
474474expect(runtime.log).toHaveBeenCalledWith("discord: gateway proxy enabled");
475475expect(runtime.error).not.toHaveBeenCalled();
476476});
@@ -498,12 +498,13 @@ describe("createDiscordGatewayPlugin", () => {
498498499499await registerGatewayClientWithMetadata({ plugin, fetchMock: globalFetchMock });
500500501-expect(globalFetchMock).toHaveBeenCalledWith(
502-"https://discord.com/api/v10/gateway/bot",
503-expect.objectContaining({
504-headers: { Authorization: "Bot token-123" },
505-}),
506-);
501+expect(globalFetchMock).toHaveBeenCalledTimes(1);
502+const fetchInit = globalFetchMock.mock.calls[0]?.[1] as
503+| { headers?: Record<string, string>; signal?: unknown }
504+| undefined;
505+expect(globalFetchMock.mock.calls[0]?.[0]).toBe("https://discord.com/api/v10/gateway/bot");
506+expect(fetchInit?.headers).toEqual({ Authorization: "Bot token-123" });
507+expect(fetchInit?.signal).toBeInstanceOf(AbortSignal);
507508expect(baseRegisterClientSpy).toHaveBeenCalledTimes(1);
508509});
509510@@ -546,7 +547,8 @@ describe("createDiscordGatewayPlugin", () => {
546547});
547548548549expect(Object.getPrototypeOf(plugin)).not.toBe(GatewayPlugin.prototype);
549-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("loopback host"));
550+expect(runtime.error).toHaveBeenCalledTimes(1);
551+expect(String(runtime.error.mock.calls[0]?.[0])).toContain("loopback host");
550552expect(runtime.log).not.toHaveBeenCalled();
551553});
552554@@ -577,8 +579,9 @@ describe("createDiscordGatewayPlugin", () => {
577579expect((plugin as unknown as { gatewayInfo?: { url?: string } }).gatewayInfo?.url).toBe(
578580"wss://gateway.discord.gg/",
579581);
580-expect(runtime.log).toHaveBeenCalledWith(
581-expect.stringContaining("discord: gateway metadata lookup failed transiently"),
582+expect(runtime.log).toHaveBeenCalledTimes(1);
583+expect(String(runtime.log.mock.calls[0]?.[0])).toContain(
584+"discord: gateway metadata lookup failed transiently",
582585);
583586});
584587此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。