diff --git a/package.json b/package.json index fb743df759..5946a116d6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index ea2c5fea9f..5b81655687 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -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( @@ -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);