@@ -13,75 +13,73 @@ 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 ,
4953 fileUri : vscode . Uri ) : Promise < boolean > {
5054
51- if ( fileUri === undefined && vscode . window . activeTextEditor === undefined ) {
52- return false ;
53- }
54-
55- const uriString = ( fileUri || vscode . window . activeTextEditor ! . document . uri ) . toString ( ) ;
56- const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
55+ const launchConfig = this . createLaunchConfig ( fileUri , launchType ) ;
5756 return this . launch ( launchConfig ) ;
5857 }
5958
6059 private async launchTests (
61- uriString : string ,
60+ fileUri : vscode . Uri ,
6261 runInDebugger : boolean ,
6362 describeBlockName ?: string ,
6463 describeBlockLineNumber ?: number ,
6564 outputPath ?: string ) : Promise < boolean > {
6665
6766 const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
68- const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
67+ const launchConfig = this . createLaunchConfig ( fileUri , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
6968 return this . launch ( launchConfig ) ;
7069 }
7170
7271 private createLaunchConfig (
73- uriString : string ,
72+ fileUri : vscode . Uri ,
7473 launchType : LaunchType ,
7574 testName ?: string ,
7675 lineNum ?: number ,
7776 outputPath ?: string ) : vscode . DebugConfiguration {
7877
79- const uri = vscode . Uri . parse ( uriString ) ;
8078 const settings = Settings . load ( ) ;
8179
8280 // Since we pass the script path to PSES in single quotes to avoid issues with PowerShell
8381 // special chars like & $ @ () [], we do have to double up the interior single quotes.
84- const scriptPath = uri . fsPath . replace ( / ' / g, "''" ) ;
82+ const scriptPath = fileUri . fsPath . replace ( / ' / g, "''" ) ;
8583
8684 const launchConfig = {
8785 request : "launch" ,
0 commit comments