@@ -18,48 +18,51 @@ export class PesterTestsFeature implements vscode.Disposable {
18
18
private invokePesterStubScriptPath : string ;
19
19
20
20
constructor ( private sessionManager : SessionManager ) {
21
- this . invokePesterStubScriptPath = path . resolve ( __dirname , "../../ modules/PowerShellEditorServices/InvokePesterStub.ps1" ) ;
21
+ this . invokePesterStubScriptPath = path . resolve ( __dirname , "../modules/PowerShellEditorServices/InvokePesterStub.ps1" ) ;
22
22
23
23
// File context-menu command - Run Pester Tests
24
24
this . command = vscode . commands . registerCommand (
25
25
"PowerShell.RunPesterTestsFromFile" ,
26
26
( fileUri ) => {
27
- this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
27
+ return this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
28
28
} ) ;
29
29
// File context-menu command - Debug Pester Tests
30
30
this . command = vscode . commands . registerCommand (
31
31
"PowerShell.DebugPesterTestsFromFile" ,
32
32
( fileUri ) => {
33
- this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
33
+ return this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
34
34
} ) ;
35
35
// This command is provided for usage by PowerShellEditorServices (PSES) only
36
36
this . command = vscode . commands . registerCommand (
37
37
"PowerShell.RunPesterTests" ,
38
38
( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ?, outputPath ?) => {
39
- this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
39
+ return this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
40
40
} ) ;
41
41
}
42
42
43
43
public dispose ( ) {
44
44
this . command . dispose ( ) ;
45
45
}
46
46
47
- private launchAllTestsInActiveEditor ( launchType : LaunchType , fileUri : vscode . Uri ) {
47
+ private async launchAllTestsInActiveEditor (
48
+ launchType : LaunchType ,
49
+ fileUri : vscode . Uri ) : Promise < boolean > {
50
+
48
51
const uriString = ( fileUri || vscode . window . activeTextEditor . document . uri ) . toString ( ) ;
49
52
const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
50
- this . launch ( launchConfig ) ;
53
+ return this . launch ( launchConfig ) ;
51
54
}
52
55
53
56
private async launchTests (
54
57
uriString : string ,
55
58
runInDebugger : boolean ,
56
59
describeBlockName ?: string ,
57
60
describeBlockLineNumber ?: number ,
58
- outputPath ?: string ) {
61
+ outputPath ?: string ) : Promise < boolean > {
59
62
60
63
const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
61
64
const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
62
- this . launch ( launchConfig ) ;
65
+ return this . launch ( launchConfig ) ;
63
66
}
64
67
65
68
private createLaunchConfig (
@@ -126,9 +129,9 @@ export class PesterTestsFeature implements vscode.Disposable {
126
129
return launchConfig ;
127
130
}
128
131
129
- private launch ( launchConfig ) {
132
+ private async launch ( launchConfig ) : Promise < boolean > {
130
133
// Create or show the interactive console
131
- // TODO #367: Check if "newSession" mode is configured
134
+ // TODO: #367 Check if "newSession" mode is configured
132
135
vscode . commands . executeCommand ( "PowerShell.ShowSessionConsole" , true ) ;
133
136
134
137
// Write out temporary debug session file
@@ -137,6 +140,10 @@ export class PesterTestsFeature implements vscode.Disposable {
137
140
this . sessionManager . getSessionDetails ( ) ) ;
138
141
139
142
// 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 ) ;
141
148
}
142
149
}
0 commit comments