22// Licensed under the MIT License.
33
44import * as path from "path" ;
5+ import * as fs from "fs" ;
56import vscode = require( "vscode" ) ;
67import { SessionManager } from "../session" ;
78import Settings = require( "../settings" ) ;
@@ -24,42 +25,45 @@ export class PesterTestsFeature implements vscode.Disposable {
2425 this . command = vscode . commands . registerCommand (
2526 "PowerShell.RunPesterTestsFromFile" ,
2627 ( fileUri ) => {
27- this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
28+ return this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
2829 } ) ;
2930 // File context-menu command - Debug Pester Tests
3031 this . command = vscode . commands . registerCommand (
3132 "PowerShell.DebugPesterTestsFromFile" ,
3233 ( fileUri ) => {
33- this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
34+ return this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
3435 } ) ;
3536 // This command is provided for usage by PowerShellEditorServices (PSES) only
3637 this . command = vscode . commands . registerCommand (
3738 "PowerShell.RunPesterTests" ,
3839 ( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ?, outputPath ?) => {
39- this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
40+ return this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
4041 } ) ;
4142 }
4243
4344 public dispose ( ) {
4445 this . command . dispose ( ) ;
4546 }
4647
47- private launchAllTestsInActiveEditor ( launchType : LaunchType , fileUri : vscode . Uri ) {
48+ private async launchAllTestsInActiveEditor (
49+ launchType : LaunchType ,
50+ fileUri : vscode . Uri ) : Promise < boolean > {
51+
4852 const uriString = ( fileUri || vscode . window . activeTextEditor . document . uri ) . toString ( ) ;
4953 const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
50- this . launch ( launchConfig ) ;
54+ return this . launch ( launchConfig ) ;
5155 }
5256
5357 private async launchTests (
5458 uriString : string ,
5559 runInDebugger : boolean ,
5660 describeBlockName ?: string ,
5761 describeBlockLineNumber ?: number ,
58- outputPath ?: string ) {
62+ outputPath ?: string ) : Promise < boolean > {
5963
6064 const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
6165 const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
62- this . launch ( launchConfig ) ;
66+ return this . launch ( launchConfig ) ;
6367 }
6468
6569 private createLaunchConfig (
@@ -126,9 +130,9 @@ export class PesterTestsFeature implements vscode.Disposable {
126130 return launchConfig ;
127131 }
128132
129- private launch ( launchConfig ) {
133+ private async launch ( launchConfig ) : Promise < boolean > {
130134 // Create or show the interactive console
131- // TODO #367: Check if "newSession" mode is configured
135+ // TODO: #367 Check if "newSession" mode is configured
132136 vscode . commands . executeCommand ( "PowerShell.ShowSessionConsole" , true ) ;
133137
134138 // Write out temporary debug session file
@@ -137,6 +141,10 @@ export class PesterTestsFeature implements vscode.Disposable {
137141 this . sessionManager . getSessionDetails ( ) ) ;
138142
139143 // TODO: Update to handle multiple root workspaces.
140- vscode . debug . startDebugging ( vscode . workspace . workspaceFolders [ 0 ] , launchConfig ) ;
144+ //
145+ // Ensure the necessary script exists (for testing). The debugger will
146+ // start regardless, but we also pass its success along.
147+ return fs . existsSync ( this . invokePesterStubScriptPath )
148+ && vscode . debug . startDebugging ( vscode . workspace . workspaceFolders [ 0 ] , launchConfig ) ;
141149 }
142150}
0 commit comments