Skip to content

Commit c72b909

Browse files
authored
Test for run plugin task command (#1256)
Will mock to verify correct command is called Issue: #1230
1 parent 6fede20 commit c72b909

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export enum Commands {
7474
RESET_PACKAGE = "swift.resetPackage",
7575
USE_LOCAL_DEPENDENCY = "swift.useLocalDependency",
7676
UNEDIT_DEPENDENCY = "swift.uneditDependency",
77+
RUN_PLUGIN_TASK = "swift.runPluginTask",
7778
}
7879

7980
/**
@@ -112,7 +113,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
112113
}),
113114
vscode.commands.registerCommand("swift.runSnippet", () => runSnippet(ctx)),
114115
vscode.commands.registerCommand("swift.debugSnippet", () => debugSnippet(ctx)),
115-
vscode.commands.registerCommand("swift.runPluginTask", () => runPluginTask()),
116+
vscode.commands.registerCommand(Commands.RUN_PLUGIN_TASK, () => runPluginTask()),
116117
vscode.commands.registerCommand("swift.restartLSPServer", () =>
117118
ctx.languageClientManager.restart()
118119
),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the VS Code Swift open source project
4+
//
5+
// Copyright (c) 2024 the VS Code Swift project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import * as vscode from "vscode";
16+
import { mockGlobalObject } from "../../MockUtils";
17+
import { expect } from "chai";
18+
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
19+
import { Commands } from "../../../src/commands";
20+
21+
suite("runPluginTask Test Suite", () => {
22+
const executeCommand = vscode.commands.executeCommand;
23+
const commandsMock = mockGlobalObject(vscode, "commands");
24+
25+
activateExtensionForSuite({
26+
async setup(ctx) {
27+
await folderInRootWorkspace("command-plugin", ctx);
28+
},
29+
});
30+
31+
test("Executes runTask command", async () => {
32+
executeCommand(Commands.RUN_PLUGIN_TASK);
33+
34+
expect(commandsMock.executeCommand).to.have.been.calledOnceWith(
35+
"workbench.action.tasks.runTask",
36+
{ type: "swift-plugin" }
37+
);
38+
});
39+
});

0 commit comments

Comments
 (0)