@@ -13,75 +13,81 @@ enum LaunchType {
1313}
1414
1515export class PesterTestsFeature implements vscode . Disposable {
16-
17- private command : vscode . Disposable ;
16+ private commands : vscode . Disposable [ ] ;
1817 private invokePesterStubScriptPath : string ;
1918
2019 constructor ( private sessionManager : SessionManager ) {
2120 this . invokePesterStubScriptPath = path . resolve ( __dirname , "../modules/PowerShellEditorServices/InvokePesterStub.ps1" ) ;
22-
23- // File context-menu command - Run Pester Tests
24- this . command = vscode . commands . registerCommand (
25- "PowerShell.RunPesterTestsFromFile" ,
26- ( fileUri ) => {
27- return this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
28- } ) ;
29- // File context-menu command - Debug Pester Tests
30- this . command = vscode . commands . registerCommand (
31- "PowerShell.DebugPesterTestsFromFile" ,
32- ( fileUri ) => {
33- return this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
34- } ) ;
35- // This command is provided for usage by PowerShellEditorServices (PSES) only
36- this . command = vscode . commands . registerCommand (
37- "PowerShell.RunPesterTests" ,
38- ( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ?, outputPath ?) => {
39- return this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
40- } ) ;
21+ this . commands = [
22+ // File context-menu command - Run Pester Tests
23+ vscode . commands . registerCommand (
24+ "PowerShell.RunPesterTestsFromFile" ,
25+ ( fileUri ?) => {
26+ return this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
27+ } ) ,
28+
29+ // File context-menu command - Debug Pester Tests
30+ vscode . commands . registerCommand (
31+ "PowerShell.DebugPesterTestsFromFile" ,
32+ ( fileUri ?) => {
33+ return this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
34+ } ) ,
35+
36+ // This command is provided for usage by PowerShellEditorServices (PSES) only
37+ vscode . commands . registerCommand (
38+ "PowerShell.RunPesterTests" ,
39+ ( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ?, outputPath ?) => {
40+ return this . launchTests ( vscode . Uri . parse ( uriString ) , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
41+ } )
42+ ] ;
4143 }
4244
4345 public dispose ( ) {
44- this . command . dispose ( ) ;
46+ for ( const command of this . commands ) {
47+ command . dispose ( ) ;
48+ }
4549 }
4650
4751 private async launchAllTestsInActiveEditor (
4852 launchType : LaunchType ,
49- fileUri : vscode . Uri ) : Promise < boolean > {
53+ fileUri ?: vscode . Uri ) : Promise < boolean > {
54+
55+ if ( fileUri === undefined ) {
56+ fileUri = vscode . window . activeTextEditor ?. document . uri ;
57+ }
5058
51- if ( fileUri === undefined && vscode . window . activeTextEditor === undefined ) {
59+ if ( fileUri === undefined ) {
5260 return false ;
5361 }
5462
55- const uriString = ( fileUri || vscode . window . activeTextEditor ! . document . uri ) . toString ( ) ;
56- const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
63+ const launchConfig = this . createLaunchConfig ( fileUri , launchType ) ;
5764 return this . launch ( launchConfig ) ;
5865 }
5966
6067 private async launchTests (
61- uriString : string ,
68+ fileUri : vscode . Uri ,
6269 runInDebugger : boolean ,
6370 describeBlockName ?: string ,
6471 describeBlockLineNumber ?: number ,
6572 outputPath ?: string ) : Promise < boolean > {
6673
6774 const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
68- const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
75+ const launchConfig = this . createLaunchConfig ( fileUri , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
6976 return this . launch ( launchConfig ) ;
7077 }
7178
7279 private createLaunchConfig (
73- uriString : string ,
80+ fileUri : vscode . Uri ,
7481 launchType : LaunchType ,
7582 testName ?: string ,
7683 lineNum ?: number ,
7784 outputPath ?: string ) : vscode . DebugConfiguration {
7885
79- const uri = vscode . Uri . parse ( uriString ) ;
8086 const settings = Settings . load ( ) ;
8187
8288 // Since we pass the script path to PSES in single quotes to avoid issues with PowerShell
8389 // special chars like & $ @ () [], we do have to double up the interior single quotes.
84- const scriptPath = uri . fsPath . replace ( / ' / g, "''" ) ;
90+ const scriptPath = fileUri . fsPath . replace ( / ' / g, "''" ) ;
8591
8692 const launchConfig = {
8793 request : "launch" ,
0 commit comments