Skip to content

Commit

Permalink
Test for run plugin task command
Browse files Browse the repository at this point in the history
Will mock to verify correct command is called

Issue: #1230
  • Loading branch information
award999 committed Dec 10, 2024
1 parent c047d4e commit af9fb24
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

/**
Expand Down Expand Up @@ -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()
),
Expand Down
39 changes: 39 additions & 0 deletions test/integration-tests/commands/runPluginTask.test.ts
Original file line number Diff line number Diff line change
@@ -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" }
);
});
});

0 comments on commit af9fb24

Please sign in to comment.