From 66421d413fa0127e7d05c3f13b895d4e25963e06 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 19:10:45 +0100 Subject: [PATCH] test: dedupe maintenance cli mock reads --- src/cli/program/register.maintenance.test.ts | 33 ++++++++------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/cli/program/register.maintenance.test.ts b/src/cli/program/register.maintenance.test.ts index 0716d0b1692..f4f783b8c86 100644 --- a/src/cli/program/register.maintenance.test.ts +++ b/src/cli/program/register.maintenance.test.ts @@ -36,6 +36,14 @@ vi.mock("../../runtime.js", () => ({ defaultRuntime: mocks.runtime, })); +function commandCall(mock: ReturnType): [typeof runtime, Record] { + const call = mock.mock.calls[0] as [typeof runtime, Record] | undefined; + if (!call) { + throw new Error("expected command call"); + } + return call; +} + describe("registerMaintenanceCommands doctor action", () => { async function runMaintenanceCli(args: string[]) { const program = new Command(); @@ -53,10 +61,7 @@ describe("registerMaintenanceCommands doctor action", () => { await runMaintenanceCli(["doctor", "--non-interactive", "--yes"]); expect(doctorCommand).toHaveBeenCalledTimes(1); - const [runtimeArg, options] = doctorCommand.mock.calls.at(0)! as unknown as [ - typeof runtime, - Record, - ]; + const [runtimeArg, options] = commandCall(doctorCommand); expect(runtimeArg).toBe(runtime); expect(options.nonInteractive).toBe(true); expect(options.yes).toBe(true); @@ -79,10 +84,7 @@ describe("registerMaintenanceCommands doctor action", () => { await runMaintenanceCli(["doctor", "--fix"]); expect(doctorCommand).toHaveBeenCalledTimes(1); - const [runtimeArg, options] = doctorCommand.mock.calls.at(0)! as unknown as [ - typeof runtime, - Record, - ]; + const [runtimeArg, options] = commandCall(doctorCommand); expect(runtimeArg).toBe(runtime); expect(options.repair).toBe(true); }); @@ -93,10 +95,7 @@ describe("registerMaintenanceCommands doctor action", () => { await runMaintenanceCli(["dashboard", "--no-open"]); expect(dashboardCommand).toHaveBeenCalledTimes(1); - const [runtimeArg, options] = dashboardCommand.mock.calls.at(0)! as unknown as [ - typeof runtime, - Record, - ]; + const [runtimeArg, options] = commandCall(dashboardCommand); expect(runtimeArg).toBe(runtime); expect(options.noOpen).toBe(true); }); @@ -114,10 +113,7 @@ describe("registerMaintenanceCommands doctor action", () => { ]); expect(resetCommand).toHaveBeenCalledTimes(1); - const [runtimeArg, options] = resetCommand.mock.calls.at(0)! as unknown as [ - typeof runtime, - Record, - ]; + const [runtimeArg, options] = commandCall(resetCommand); expect(runtimeArg).toBe(runtime); expect(options.scope).toBe("full"); expect(options.yes).toBe(true); @@ -141,10 +137,7 @@ describe("registerMaintenanceCommands doctor action", () => { ]); expect(uninstallCommand).toHaveBeenCalledTimes(1); - const [runtimeArg, options] = uninstallCommand.mock.calls.at(0)! as unknown as [ - typeof runtime, - Record, - ]; + const [runtimeArg, options] = commandCall(uninstallCommand); expect(runtimeArg).toBe(runtime); expect(options.service).toBe(true); expect(options.state).toBe(true);