























@@ -40,6 +40,14 @@ const FAKE_CHILD = {
4040pid: 1234,
4141} as unknown as import("node:child_process").ChildProcess;
424243+function firstMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] {
44+const call = mock.mock.calls[0];
45+if (!call) {
46+throw new Error(`Expected ${label} to be called`);
47+}
48+return call;
49+}
50+4351describe("spawnLspServerProcess Windows .cmd shim handling", () => {
4452beforeEach(() => {
4553vi.clearAllMocks();
@@ -66,7 +74,7 @@ describe("spawnLspServerProcess Windows .cmd shim handling", () => {
6674});
67756876// Must use structured params so config.env entries are not dropped
69-const sanitizeParams = sanitizeHostExecEnvMock.mock.calls.at(0)?.[0] as
77+const sanitizeParams = firstMockCall(sanitizeHostExecEnvMock, "host env sanitization")[0] as
7078| { baseEnv?: NodeJS.ProcessEnv; overrides?: Record<string, string> }
7179| undefined;
7280expect(sanitizeParams?.baseEnv).toBe(process.env);
@@ -87,9 +95,10 @@ describe("spawnLspServerProcess Windows .cmd shim handling", () => {
87958896spawnLspServerProcess({ command: "typescript-language-server", args: ["--stdio"] });
899790-const resolveParams = resolveWindowsSpawnProgramMock.mock.calls.at(0)?.[0] as
91-| { env?: Record<string, string>; allowShellFallback?: boolean }
92-| undefined;
98+const resolveParams = firstMockCall(
99+resolveWindowsSpawnProgramMock,
100+"Windows spawn resolution",
101+)[0] as { env?: Record<string, string>; allowShellFallback?: boolean } | undefined;
93102expect(resolveParams?.env).toBe(sanitizedEnv);
94103expect(resolveParams?.allowShellFallback).toBe(true);
95104});
@@ -108,7 +117,7 @@ describe("spawnLspServerProcess Windows .cmd shim handling", () => {
108117109118spawnLspServerProcess({ command: "typescript-language-server", args: ["--stdio"] });
110119111-const spawnCall = spawnMock.mock.calls.at(0);
120+const spawnCall = firstMockCall(spawnMock, "child process spawn");
112121expect(spawnCall?.[0]).toBe("cmd.exe");
113122expect(spawnCall?.[1]).toEqual(["/c", "typescript-language-server.cmd", "--stdio"]);
114123const spawnOptions = spawnCall?.[2] as
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。