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