@@ -18,48 +18,51 @@ export class PesterTestsFeature implements vscode.Disposable {
1818 private invokePesterStubScriptPath : string ;
1919
2020 constructor ( private sessionManager : SessionManager ) {
21- this . invokePesterStubScriptPath = path . resolve ( __dirname , "../../ modules/PowerShellEditorServices/InvokePesterStub.ps1" ) ;
21+ this . invokePesterStubScriptPath = path . resolve ( __dirname , "../modules/PowerShellEditorServices/InvokePesterStub.ps1" ) ;
2222
2323 // File context-menu command - Run Pester Tests
2424 this . command = vscode . commands . registerCommand (
2525 "PowerShell.RunPesterTestsFromFile" ,
2626 ( fileUri ) => {
27- this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
27+ return this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
2828 } ) ;
2929 // File context-menu command - Debug Pester Tests
3030 this . command = vscode . commands . registerCommand (
3131 "PowerShell.DebugPesterTestsFromFile" ,
3232 ( fileUri ) => {
33- this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
33+ return this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
3434 } ) ;
3535 // This command is provided for usage by PowerShellEditorServices (PSES) only
3636 this . command = vscode . commands . registerCommand (
3737 "PowerShell.RunPesterTests" ,
3838 ( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ?, outputPath ?) => {
39- this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
39+ return this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
4040 } ) ;
4141 }
4242
4343 public dispose ( ) {
4444 this . command . dispose ( ) ;
4545 }
4646
47- private launchAllTestsInActiveEditor ( launchType : LaunchType , fileUri : vscode . Uri ) {
47+ private async launchAllTestsInActiveEditor (
48+ launchType : LaunchType ,
49+ fileUri : vscode . Uri ) : Promise < boolean > {
50+
4851 const uriString = ( fileUri || vscode . window . activeTextEditor . document . uri ) . toString ( ) ;
4952 const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
50- this . launch ( launchConfig ) ;
53+ return this . launch ( launchConfig ) ;
5154 }
5255
5356 private async launchTests (
5457 uriString : string ,
5558 runInDebugger : boolean ,
5659 describeBlockName ?: string ,
5760 describeBlockLineNumber ?: number ,
58- outputPath ?: string ) {
61+ outputPath ?: string ) : Promise < boolean > {
5962
6063 const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
6164 const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
62- this . launch ( launchConfig ) ;
65+ return this . launch ( launchConfig ) ;
6366 }
6467
6568 private createLaunchConfig (
@@ -126,9 +129,9 @@ export class PesterTestsFeature implements vscode.Disposable {
126129 return launchConfig ;
127130 }
128131
129- private launch ( launchConfig ) {
132+ private async launch ( launchConfig ) : Promise < boolean > {
130133 // Create or show the interactive console
131- // TODO #367: Check if "newSession" mode is configured
134+ // TODO: #367 Check if "newSession" mode is configured
132135 vscode . commands . executeCommand ( "PowerShell.ShowSessionConsole" , true ) ;
133136
134137 // Write out temporary debug session file
@@ -137,6 +140,10 @@ export class PesterTestsFeature implements vscode.Disposable {
137140 this . sessionManager . getSessionDetails ( ) ) ;
138141
139142 // TODO: Update to handle multiple root workspaces.
140- vscode . debug . startDebugging ( vscode . workspace . workspaceFolders [ 0 ] , launchConfig ) ;
143+ //
144+ // Ensure the necessary script exists (for testing). The debugger will
145+ // start regardless, but we also pass its success along.
146+ return utils . fileExists ( this . invokePesterStubScriptPath )
147+ && vscode . debug . startDebugging ( vscode . workspace . workspaceFolders [ 0 ] , launchConfig ) ;
141148 }
142149}
0 commit comments