Skip to content

Commit

Permalink
Add explorer context menus for 'Run/Debug Pester tests' (#2445)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bergmeister committed Feb 3, 2020
1 parent ab94b61 commit bf0c48b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@
"when": "false"
}
],
"explorer/context": [
{
"command": "PowerShell.RunPesterTestsFromFile",
"when": "resourceFilename =~ /\\.tests\\.ps1$/i"
},
{
"command": "PowerShell.DebugPesterTestsFromFile",
"when": "resourceFilename =~ /\\.tests\\.ps1$/i"
}
],
"editor/context": [
{
"when": "editorLangId == powershell",
Expand Down
12 changes: 6 additions & 6 deletions src/features/PesterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export class PesterTestsFeature implements IFeature {
// File context-menu command - Run Pester Tests
this.command = vscode.commands.registerCommand(
"PowerShell.RunPesterTestsFromFile",
() => {
this.launchAllTestsInActiveEditor(LaunchType.Run);
(fileUri) => {
this.launchAllTestsInActiveEditor(LaunchType.Run, fileUri);
});
// File context-menu command - Debug Pester Tests
this.command = vscode.commands.registerCommand(
"PowerShell.DebugPesterTestsFromFile",
() => {
this.launchAllTestsInActiveEditor(LaunchType.Debug);
(fileUri) => {
this.launchAllTestsInActiveEditor(LaunchType.Debug, fileUri);
});
// This command is provided for usage by PowerShellEditorServices (PSES) only
this.command = vscode.commands.registerCommand(
Expand All @@ -51,8 +51,8 @@ export class PesterTestsFeature implements IFeature {
this.languageClient = languageClient;
}

private launchAllTestsInActiveEditor(launchType: LaunchType) {
const uriString = vscode.window.activeTextEditor.document.uri.toString();
private launchAllTestsInActiveEditor(launchType: LaunchType, fileUri: vscode.Uri) {
const uriString = fileUri.toString();
const launchConfig = this.createLaunchConfig(uriString, launchType);
launchConfig.args.push("-All");
this.launch(launchConfig);
Expand Down

0 comments on commit bf0c48b

Please sign in to comment.