From afd307091c9c3e60c6dcecd17d03e3c0b843832d Mon Sep 17 00:00:00 2001 From: Adam Ward Date: Tue, 10 Dec 2024 13:06:00 -0500 Subject: [PATCH] Test for run plugin task command Will mock to verify correct command is called Issue: #1230 --- src/commands.ts | 3 +- .../commands/runPluginTask.test.ts | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/integration-tests/commands/runPluginTask.test.ts diff --git a/src/commands.ts b/src/commands.ts index 63be024dd..7f6fed973 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -74,6 +74,7 @@ export enum Commands { RESET_PACKAGE = "swift.resetPackage", USE_LOCAL_DEPENDENCY = "swift.useLocalDependency", UNEDIT_DEPENDENCY = "swift.uneditDependency", + RUN_PLUGIN_TASK = "swift.runPluginTask", } /** @@ -112,7 +113,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] { }), vscode.commands.registerCommand("swift.runSnippet", () => runSnippet(ctx)), vscode.commands.registerCommand("swift.debugSnippet", () => debugSnippet(ctx)), - vscode.commands.registerCommand("swift.runPluginTask", () => runPluginTask()), + vscode.commands.registerCommand(Commands.RUN_PLUGIN_TASK, () => runPluginTask()), vscode.commands.registerCommand("swift.restartLSPServer", () => ctx.languageClientManager.restart() ), diff --git a/test/integration-tests/commands/runPluginTask.test.ts b/test/integration-tests/commands/runPluginTask.test.ts new file mode 100644 index 000000000..51b291cb8 --- /dev/null +++ b/test/integration-tests/commands/runPluginTask.test.ts @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the VS Code Swift open source project +// +// Copyright (c) 2024 the VS Code Swift project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of VS Code Swift project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import * as vscode from "vscode"; +import { mockGlobalObject } from "../../MockUtils"; +import { expect } from "chai"; +import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities"; +import { Commands } from "../../../src/commands"; + +suite("runPluginTask Test Suite", () => { + const executeCommand = vscode.commands.executeCommand; + const commandsMock = mockGlobalObject(vscode, "commands"); + + activateExtensionForSuite({ + async setup(ctx) { + await folderInRootWorkspace("command-plugin", ctx); + }, + }); + + test("Executes runTask command", async () => { + executeCommand(Commands.RUN_PLUGIN_TASK); + + expect(commandsMock.executeCommand).to.have.been.calledOnceWith( + "workbench.action.tasks.runTask", + { type: "swift-plugin" } + ); + }); +});