From a3ff7aa02ca1a2a6bc129d341be44cf02812e4f3 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 22:59:34 +0100 Subject: [PATCH] test: dedupe run node mock reads --- src/infra/run-node.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/infra/run-node.test.ts b/src/infra/run-node.test.ts index c13b11c1dd9..c319f892dd5 100644 --- a/src/infra/run-node.test.ts +++ b/src/infra/run-node.test.ts @@ -123,6 +123,10 @@ function createFakeProcess() { }) as unknown as NodeJS.Process; } +function firstMockCall(mock: { mock: { calls: T[] } }): T | undefined { + return mock.mock.calls[0]; +} + async function writeRuntimePostBuildScaffold(tmp: string): Promise { const pluginSdkAliasPath = path.join(tmp, "src", "plugin-sdk", "root-alias.cjs"); await fs.mkdir(path.dirname(pluginSdkAliasPath), { recursive: true }); @@ -847,7 +851,7 @@ describe("run-node script", () => { expect(exitCode).toBe(0); expect(runRuntimePostBuild).toHaveBeenCalledTimes(1); - const postBuildParams = runRuntimePostBuild.mock.calls.at(0)?.[0] as + const postBuildParams = firstMockCall(runRuntimePostBuild)?.[0] as | { cwd?: string; env?: Record } | undefined; expect(postBuildParams?.cwd).toBe(tmp); @@ -1328,9 +1332,7 @@ describe("run-node script", () => { expect(exitCode).toBe(143); expect(spawn).toHaveBeenCalledTimes(1); - const spawnCall = spawn.mock.calls.at(0) as - | [string, string[], { stdio?: unknown }] - | undefined; + const spawnCall = firstMockCall(spawn) as [string, string[], { stdio?: unknown }] | undefined; expect(spawnCall?.[0]).toBe(process.execPath); expect(spawnCall?.[1]).toEqual(["openclaw.mjs", "status"]); expect(spawnCall?.[2].stdio).toBe("inherit");