

















@@ -291,6 +291,15 @@ vi.mock("./config-reload.js", async (importOriginal) => {
291291292292installGatewayTestHooks({ scope: "suite" });
293293294+function latestMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] {
295+const calls = mock.mock.calls;
296+const call = calls[calls.length - 1];
297+if (!call) {
298+throw new Error(`expected ${label} call`);
299+}
300+return call;
301+}
302+294303async function waitForGatewayAuthChangedClose(ws: WebSocket): Promise<{
295304code: number;
296305reason: string;
@@ -704,21 +713,21 @@ describe("gateway hot reload", () => {
704713);
705714706715expect(hoisted.stopGmailWatcher).toHaveBeenCalled();
707-const restartedGmailCall = hoisted.startGmailWatcher.mock.calls.at(-1) as
708-| [typeof nextConfig]
709-| undefined;
710-const restartedGmailConfig = restartedGmailCall?.[0];
711-expect(restartedGmailConfig?.hooks).toEqual(nextConfig.hooks);
712-expect(restartedGmailConfig?.channels).toEqual(nextConfig.channels);
716+const [restartedGmailConfig] = latestMockCall(
717+hoisted.startGmailWatcher,
718+"Gmail watcher start",
719+) as [typeof nextConfig];
720+expect(restartedGmailConfig.hooks).toEqual(nextConfig.hooks);
721+expect(restartedGmailConfig.channels).toEqual(nextConfig.channels);
713722714723expect(hoisted.startHeartbeatRunner).toHaveBeenCalledTimes(1);
715724expect(hoisted.heartbeatUpdateConfig).toHaveBeenCalledTimes(1);
716-const heartbeatUpdateCall = hoisted.heartbeatUpdateConfig.mock.calls.at(-1) as
717-| [typeof nextConfig]
718-| undefined;
719-const heartbeatConfig = heartbeatUpdateCall?.[0];
720-expect(heartbeatConfig?.agents).toEqual(nextConfig.agents);
721-expect(heartbeatConfig?.web).toEqual(nextConfig.web);
725+const [heartbeatConfig] = latestMockCall(
726+hoisted.heartbeatUpdateConfig,
727+"heartbeat config update",
728+) as [typeof nextConfig];
729+expect(heartbeatConfig.agents).toEqual(nextConfig.agents);
730+expect(heartbeatConfig.web).toEqual(nextConfig.web);
722731723732await vi.waitFor(() => {
724733expect(hoisted.cronInstances.length).toBeGreaterThanOrEqual(1);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。