





















@@ -94,11 +94,19 @@ describe.runIf(process.platform !== "win32")("findGatewayPidsOnPortSync", () =>
9494const pids = findGatewayPidsOnPortSync(18789);
95959696expect(pids).toEqual([gatewayPidA, gatewayPidB]);
97-expect(spawnSyncMock).toHaveBeenCalledWith(
98-"/usr/sbin/lsof",
99-["-nP", "-iTCP:18789", "-sTCP:LISTEN", "-Fpc"],
100-expect.objectContaining({ encoding: "utf8", timeout: 2000 }),
97+const [command, args, options] =
98+spawnSyncMock.mock.calls.find(
99+([spawnCommand, spawnArgs]) =>
100+spawnCommand === "/usr/sbin/lsof" &&
101+Array.isArray(spawnArgs) &&
102+spawnArgs.includes("-iTCP:18789"),
103+) ?? [];
104+expect(command).toBe("/usr/sbin/lsof");
105+expect(args).toEqual(["-nP", "-iTCP:18789", "-sTCP:LISTEN", "-Fpc"]);
106+expect((options as { encoding?: unknown; timeout?: unknown } | undefined)?.encoding).toBe(
107+"utf8",
101108);
109+expect((options as { encoding?: unknown; timeout?: unknown } | undefined)?.timeout).toBe(2000);
102110});
103111104112it("returns empty when lsof fails", () => {
@@ -159,11 +167,14 @@ describe.runIf(process.platform !== "win32")("cleanStaleGatewayProcessesSync", (
159167160168expect(killed).toEqual([stalePid]);
161169expect(resolveGatewayPortMock).not.toHaveBeenCalled();
162-expect(spawnSyncMock).toHaveBeenCalledWith(
163-"/usr/sbin/lsof",
164-["-nP", "-iTCP:19999", "-sTCP:LISTEN", "-Fpc"],
165-expect.objectContaining({ encoding: "utf8", timeout: 2000 }),
170+expect(spawnSyncMock).toHaveBeenCalledTimes(2);
171+const [command, args, options] = spawnSyncMock.mock.calls[0] ?? [];
172+expect(command).toBe("/usr/sbin/lsof");
173+expect(args).toEqual(["-nP", "-iTCP:19999", "-sTCP:LISTEN", "-Fpc"]);
174+expect((options as { encoding?: unknown; timeout?: unknown } | undefined)?.encoding).toBe(
175+"utf8",
166176);
177+expect((options as { encoding?: unknown; timeout?: unknown } | undefined)?.timeout).toBe(2000);
167178expect(killSpy).toHaveBeenCalledWith(stalePid, "SIGTERM");
168179expect(killSpy).toHaveBeenCalledWith(stalePid, "SIGKILL");
169180});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。