From 7fd5d45ae4eaec89c17de024ec4f22de8a08a721 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 04:48:31 +0100 Subject: [PATCH] test: guard shell env mock calls --- src/infra/shell-env.test.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/infra/shell-env.test.ts b/src/infra/shell-env.test.ts index 82fe63a7f1a..ce14462d825 100644 --- a/src/infra/shell-env.test.ts +++ b/src/infra/shell-env.test.ts @@ -94,6 +94,14 @@ describe("shell env fallback", () => { } } + function requireExecCall(exec: ReturnType): unknown[] { + const call = exec.mock.calls.at(0); + if (!call) { + throw new Error("expected shell env exec call"); + } + return call; + } + function getShellPathTwiceWithExec(params: { exec: ReturnType; platform: NodeJS.Platform; @@ -114,7 +122,7 @@ describe("shell env fallback", () => { function expectBinShFallbackExec(exec: ReturnType) { expect(exec).toHaveBeenCalledTimes(1); - const [shell, args, options] = exec.mock.calls[0] as unknown[]; + const [shell, args, options] = requireExecCall(exec); expect(shell).toBe("/bin/sh"); expect(args).toStrictEqual(["-l", "-c", "env -0"]); expect((options as { windowsHide?: unknown } | undefined)?.windowsHide).toBe(true); @@ -427,7 +435,7 @@ describe("shell env fallback", () => { expect(res.ok).toBe(true); expect(exec).toHaveBeenCalledTimes(1); - const [shell, args, options] = exec.mock.calls[0] as unknown[]; + const [shell, args, options] = requireExecCall(exec); expect(shell).toBe(trustedShell); expect(args).toStrictEqual(["-l", "-c", "env -0"]); expect((options as { windowsHide?: unknown } | undefined)?.windowsHide).toBe(true);