Skip to content

Commit bf0c48b

Browse files
authored
Add explorer context menus for 'Run/Debug Pester tests' (#2445)
* Add explorer context menus for 'Run/Debug Pester tests' * Make context menu work using file from selected tab/explorer menu * 🧹 Cleanup: Make fileUri non-optional
1 parent ab94b61 commit bf0c48b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@
287287
"when": "false"
288288
}
289289
],
290+
"explorer/context": [
291+
{
292+
"command": "PowerShell.RunPesterTestsFromFile",
293+
"when": "resourceFilename =~ /\\.tests\\.ps1$/i"
294+
},
295+
{
296+
"command": "PowerShell.DebugPesterTestsFromFile",
297+
"when": "resourceFilename =~ /\\.tests\\.ps1$/i"
298+
}
299+
],
290300
"editor/context": [
291301
{
292302
"when": "editorLangId == powershell",

src/features/PesterTests.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ export class PesterTestsFeature implements IFeature {
2626
// File context-menu command - Run Pester Tests
2727
this.command = vscode.commands.registerCommand(
2828
"PowerShell.RunPesterTestsFromFile",
29-
() => {
30-
this.launchAllTestsInActiveEditor(LaunchType.Run);
29+
(fileUri) => {
30+
this.launchAllTestsInActiveEditor(LaunchType.Run, fileUri);
3131
});
3232
// File context-menu command - Debug Pester Tests
3333
this.command = vscode.commands.registerCommand(
3434
"PowerShell.DebugPesterTestsFromFile",
35-
() => {
36-
this.launchAllTestsInActiveEditor(LaunchType.Debug);
35+
(fileUri) => {
36+
this.launchAllTestsInActiveEditor(LaunchType.Debug, fileUri);
3737
});
3838
// This command is provided for usage by PowerShellEditorServices (PSES) only
3939
this.command = vscode.commands.registerCommand(
@@ -51,8 +51,8 @@ export class PesterTestsFeature implements IFeature {
5151
this.languageClient = languageClient;
5252
}
5353

54-
private launchAllTestsInActiveEditor(launchType: LaunchType) {
55-
const uriString = vscode.window.activeTextEditor.document.uri.toString();
54+
private launchAllTestsInActiveEditor(launchType: LaunchType, fileUri: vscode.Uri) {
55+
const uriString = fileUri.toString();
5656
const launchConfig = this.createLaunchConfig(uriString, launchType);
5757
launchConfig.args.push("-All");
5858
this.launch(launchConfig);

0 commit comments

Comments
 (0)