

























@@ -7,6 +7,17 @@ vi.mock("../../commands/health.js", () => ({
77getHealthSnapshot: getHealthSnapshotMock,
88}));
9910+function healthSnapshotCallArg(index = 0) {
11+return getHealthSnapshotMock.mock.calls.at(index)?.at(0) as
12+| {
13+eventLoop?: unknown;
14+includeSensitive?: boolean;
15+probe?: boolean;
16+runtimeSnapshot?: unknown;
17+}
18+| undefined;
19+}
20+1021function createHealthSummary(): HealthSummary {
1122return {
1223ok: true,
@@ -57,7 +68,7 @@ describe("refreshGatewayHealthSnapshot", () => {
5768includeSensitive: false,
5869runtimeSnapshot: undefined,
5970});
60-expect(Object.hasOwn(getHealthSnapshotMock.mock.calls[0]?.[0] ?? {}, "eventLoop")).toBe(false);
71+expect(Object.hasOwn(healthSnapshotCallArg() ?? {}, "eventLoop")).toBe(false);
6172resolveSnapshot?.(createHealthSummary());
6273await expect(Promise.all([first, second])).resolves.toHaveLength(2);
6374});
@@ -84,8 +95,8 @@ describe("refreshGatewayHealthSnapshot", () => {
8495});
85968697expect(getHealthSnapshotMock).toHaveBeenCalledTimes(2);
87-expect(getHealthSnapshotMock.mock.calls[0]?.[0]?.eventLoop).toBe(eventLoop);
88-expect(Object.hasOwn(getHealthSnapshotMock.mock.calls[1]?.[0] ?? {}, "eventLoop")).toBe(false);
98+expect(healthSnapshotCallArg()?.eventLoop).toBe(eventLoop);
99+expect(Object.hasOwn(healthSnapshotCallArg(1) ?? {}, "eventLoop")).toBe(false);
89100});
9010191102it("captures runtime snapshots for completed refreshes and guards snapshot failures", async () => {
@@ -109,15 +120,16 @@ describe("refreshGatewayHealthSnapshot", () => {
109120expect(getHealthSnapshotMock).toHaveBeenCalledTimes(2);
110121expect(
111122getHealthSnapshotMock.mock.calls
112-.map((call) => call[0]?.probe)
123+.map((_call, index) => healthSnapshotCallArg(index)?.probe)
113124.toSorted((a, b) => Number(a) - Number(b)),
114125).toEqual([false, true]);
115-expect(getHealthSnapshotMock.mock.calls.map((call) => call[0]?.includeSensitive)).toEqual([
116-false,
117-false,
118-]);
119-expect(getHealthSnapshotMock.mock.calls[0]?.[0]?.runtimeSnapshot).toBe(runtimeSnapshot);
120-expect(getHealthSnapshotMock.mock.calls[1]?.[0]?.runtimeSnapshot).toBeUndefined();
126+expect(
127+getHealthSnapshotMock.mock.calls.map(
128+(_call, index) => healthSnapshotCallArg(index)?.includeSensitive,
129+),
130+).toEqual([false, false]);
131+expect(healthSnapshotCallArg()?.runtimeSnapshot).toBe(runtimeSnapshot);
132+expect(healthSnapshotCallArg(1)?.runtimeSnapshot).toBeUndefined();
121133});
122134123135it("does not cache or broadcast sensitive health refreshes", async () => {
@@ -171,8 +183,8 @@ describe("refreshGatewayHealthSnapshot", () => {
171183const safe = healthState.refreshGatewayHealthSnapshot({ probe: false });
172184173185expect(getHealthSnapshotMock).toHaveBeenCalledTimes(2);
174-expect(getHealthSnapshotMock.mock.calls[0]?.[0]?.includeSensitive).toBe(true);
175-expect(getHealthSnapshotMock.mock.calls[1]?.[0]?.includeSensitive).toBe(false);
186+expect(healthSnapshotCallArg()?.includeSensitive).toBe(true);
187+expect(healthSnapshotCallArg(1)?.includeSensitive).toBe(false);
176188177189resolveSensitive?.();
178190resolveSafe?.();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。