@@ -18,8 +18,11 @@ export class PesterTestsFeature implements IFeature {
18
18
19
19
private command : vscode . Disposable ;
20
20
private languageClient : LanguageClient ;
21
+ private invokePesterStubScriptPath : string ;
21
22
22
23
constructor ( private sessionManager : SessionManager ) {
24
+ this . invokePesterStubScriptPath = path . resolve ( __dirname , "../../../InvokePesterStub.ps1" ) ;
25
+
23
26
// File context-menu command - Run Pester Tests
24
27
this . command = vscode . commands . registerCommand (
25
28
"PowerShell.RunPesterTestsFromFile" ,
@@ -35,8 +38,8 @@ export class PesterTestsFeature implements IFeature {
35
38
// This command is provided for usage by PowerShellEditorServices (PSES) only
36
39
this . command = vscode . commands . registerCommand (
37
40
"PowerShell.RunPesterTests" ,
38
- ( uriString , runInDebugger , describeBlockName ?) => {
39
- this . launchTests ( uriString , runInDebugger , describeBlockName ) ;
41
+ ( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ? ) => {
42
+ this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber ) ;
40
43
} ) ;
41
44
}
42
45
@@ -51,38 +54,22 @@ export class PesterTestsFeature implements IFeature {
51
54
private launchAllTestsInActiveEditor ( launchType : LaunchType ) {
52
55
const uriString = vscode . window . activeTextEditor . document . uri . toString ( ) ;
53
56
const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
57
+ launchConfig . args . push ( "-All" ) ;
54
58
this . launch ( launchConfig ) ;
55
59
}
56
60
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 !== "Yes" ) {
66
- return ;
67
- }
68
- }
61
+ private async launchTests (
62
+ uriString : string ,
63
+ runInDebugger : boolean ,
64
+ describeBlockName ?: string ,
65
+ describeBlockLineNumber ?: number ) {
69
66
70
67
const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
71
- const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
72
-
73
- if ( describeBlockName ) {
74
- launchConfig . args . push ( "-TestName" ) ;
75
- // Escape single quotes inside double quotes by doubling them up
76
- if ( describeBlockName . includes ( "'" ) ) {
77
- describeBlockName = describeBlockName . replace ( / ' / g, "''" ) ;
78
- }
79
- launchConfig . args . push ( `'${ describeBlockName } '` ) ;
80
- }
81
-
68
+ const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , describeBlockLineNumber ) ;
82
69
this . launch ( launchConfig ) ;
83
70
}
84
71
85
- private createLaunchConfig ( uriString : string , launchType : LaunchType ) {
72
+ private createLaunchConfig ( uriString : string , launchType : LaunchType , testName ?: string , lineNum ?: number ) {
86
73
const uri = vscode . Uri . parse ( uriString ) ;
87
74
const currentDocument = vscode . window . activeTextEditor . document ;
88
75
const settings = Settings . load ( ) ;
@@ -95,12 +82,10 @@ export class PesterTestsFeature implements IFeature {
95
82
request : "launch" ,
96
83
type : "PowerShell" ,
97
84
name : "PowerShell Launch Pester Tests" ,
98
- script : "Invoke-Pester" ,
85
+ script : this . invokePesterStubScriptPath ,
99
86
args : [
100
- "-Script " ,
87
+ "-ScriptPath " ,
101
88
`'${ scriptPath } '` ,
102
- "-PesterOption" ,
103
- "@{IncludeVSCodeMarker=$true}" ,
104
89
] ,
105
90
internalConsoleOptions : "neverOpen" ,
106
91
noDebug : ( launchType === LaunchType . Run ) ,
@@ -111,6 +96,19 @@ export class PesterTestsFeature implements IFeature {
111
96
: path . dirname ( currentDocument . fileName ) ,
112
97
} ;
113
98
99
+ if ( lineNum ) {
100
+ launchConfig . args . push ( "-LineNumber" , `${ lineNum } ` ) ;
101
+ }
102
+
103
+ if ( testName ) {
104
+ // Escape single quotes inside double quotes by doubling them up
105
+ if ( testName . includes ( "'" ) ) {
106
+ testName = testName . replace ( / ' / g, "''" ) ;
107
+ }
108
+
109
+ launchConfig . args . push ( "-TestName" , `'${ testName } '` ) ;
110
+ }
111
+
114
112
return launchConfig ;
115
113
}
116
114
0 commit comments