@@ -9,21 +9,28 @@ import { SessionManager } from "../session";
9
9
import Settings = require( "../settings" ) ;
10
10
import utils = require( "../utils" ) ;
11
11
12
+ enum LaunchType {
13
+ Debug ,
14
+ Run ,
15
+ }
16
+
12
17
export class PesterTestsFeature implements IFeature {
13
18
14
19
private command : vscode . Disposable ;
15
20
private languageClient : LanguageClient ;
16
21
17
22
constructor ( private sessionManager : SessionManager ) {
23
+ // File context-menu command - Run Pester Tests
18
24
this . command = vscode . commands . registerCommand (
19
25
"PowerShell.RunPesterTestsFromFile" ,
20
26
( ) => {
21
- this . launchTests ( vscode . window . activeTextEditor . document . uri , false ) ;
27
+ this . launchAllTestsInActiveEditor ( LaunchType . Run ) ;
22
28
} ) ;
29
+ // File context-menu command - Debug Pester Tests
23
30
this . command = vscode . commands . registerCommand (
24
31
"PowerShell.DebugPesterTestsFromFile" ,
25
32
( ) => {
26
- this . launchTests ( vscode . window . activeTextEditor . document . uri , true ) ;
33
+ this . launchAllTestsInActiveEditor ( LaunchType . Debug ) ;
27
34
} ) ;
28
35
// This command is provided for usage by PowerShellEditorServices (PSES) only
29
36
this . command = vscode . commands . registerCommand (
@@ -41,7 +48,37 @@ export class PesterTestsFeature implements IFeature {
41
48
this . languageClient = languageClient ;
42
49
}
43
50
44
- private launchTests ( uriString , runInDebugger , describeBlockName ?) {
51
+ private launchAllTestsInActiveEditor ( launchType : LaunchType ) {
52
+ const uriString = vscode . window . activeTextEditor . document . uri . toString ( ) ;
53
+ const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
54
+ this . launch ( launchConfig ) ;
55
+ }
56
+
57
+ private async launchTests ( uriString : string , runInDebugger : boolean , describeBlockName ?: string ) {
58
+ // PSES passes null for the describeBlockName to signal that it can't evaluate the TestName.
59
+ if ( ! describeBlockName ) {
60
+ const answer = await vscode . window . showErrorMessage (
61
+ "This Describe block's TestName parameter cannot be evaluated. " +
62
+ `Would you like to ${ runInDebugger ? "debug" : "run" } all the tests in this file?` ,
63
+ "Yes" , "No" ) ;
64
+
65
+ if ( answer === "No" ) {
66
+ return ;
67
+ }
68
+ }
69
+
70
+ const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
71
+ const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
72
+
73
+ if ( describeBlockName ) {
74
+ launchConfig . args . push ( "-TestName" ) ;
75
+ launchConfig . args . push ( `'${ describeBlockName } '` ) ;
76
+ }
77
+
78
+ this . launch ( launchConfig ) ;
79
+ }
80
+
81
+ private createLaunchConfig ( uriString : string , launchType : LaunchType ) {
45
82
const uri = vscode . Uri . parse ( uriString ) ;
46
83
const currentDocument = vscode . window . activeTextEditor . document ;
47
84
const settings = Settings . load ( ) ;
@@ -62,19 +99,18 @@ export class PesterTestsFeature implements IFeature {
62
99
"@{IncludeVSCodeMarker=$true}" ,
63
100
] ,
64
101
internalConsoleOptions : "neverOpen" ,
65
- noDebug : ! runInDebugger ,
102
+ noDebug : ( launchType === LaunchType . Run ) ,
66
103
createTemporaryIntegratedConsole : settings . debugging . createTemporaryIntegratedConsole ,
67
104
cwd :
68
105
currentDocument . isUntitled
69
106
? vscode . workspace . rootPath
70
107
: path . dirname ( currentDocument . fileName ) ,
71
108
} ;
72
109
73
- if ( describeBlockName ) {
74
- launchConfig . args . push ( "-TestName" ) ;
75
- launchConfig . args . push ( `'${ describeBlockName } '` ) ;
76
- }
110
+ return launchConfig ;
111
+ }
77
112
113
+ private launch ( launchConfig ) {
78
114
// Create or show the interactive console
79
115
// TODO #367: Check if "newSession" mode is configured
80
116
vscode . commands . executeCommand ( "PowerShell.ShowSessionConsole" , true ) ;
0 commit comments