@@ -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
@@ -54,7 +57,7 @@ export class PesterTestsFeature implements IFeature {
54
57
this . launch ( launchConfig ) ;
55
58
}
56
59
57
- private async launchTests ( uriString : string , runInDebugger : boolean , describeBlockName ?: string ) {
60
+ private async launchTests ( uriString : string , runInDebugger : boolean , describeBlockName ?: string , lineNum ?: number ) {
58
61
// PSES passes null for the describeBlockName to signal that it can't evaluate the TestName.
59
62
if ( ! describeBlockName ) {
60
63
const answer = await vscode . window . showErrorMessage (
@@ -68,21 +71,11 @@ export class PesterTestsFeature implements IFeature {
68
71
}
69
72
70
73
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
-
74
+ const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , lineNum ) ;
82
75
this . launch ( launchConfig ) ;
83
76
}
84
77
85
- private createLaunchConfig ( uriString : string , launchType : LaunchType ) {
78
+ private createLaunchConfig ( uriString : string , launchType : LaunchType , testName ?: string , lineNum ?: number ) {
86
79
const uri = vscode . Uri . parse ( uriString ) ;
87
80
const currentDocument = vscode . window . activeTextEditor . document ;
88
81
const settings = Settings . load ( ) ;
@@ -95,12 +88,10 @@ export class PesterTestsFeature implements IFeature {
95
88
request : "launch" ,
96
89
type : "PowerShell" ,
97
90
name : "PowerShell Launch Pester Tests" ,
98
- script : "Invoke-Pester" ,
91
+ script : this . invokePesterStubScriptPath ,
99
92
args : [
100
- "-Script " ,
93
+ "-ScriptPath " ,
101
94
`'${ scriptPath } '` ,
102
- "-PesterOption" ,
103
- "@{IncludeVSCodeMarker=$true}" ,
104
95
] ,
105
96
internalConsoleOptions : "neverOpen" ,
106
97
noDebug : ( launchType === LaunchType . Run ) ,
@@ -111,6 +102,19 @@ export class PesterTestsFeature implements IFeature {
111
102
: path . dirname ( currentDocument . fileName ) ,
112
103
} ;
113
104
105
+ if ( lineNum ) {
106
+ launchConfig . args . push ( "-LineNumber" , `${ lineNum } ` ) ;
107
+ }
108
+
109
+ if ( testName ) {
110
+ // Escape single quotes inside double quotes by doubling them up
111
+ if ( testName . includes ( "'" ) ) {
112
+ testName = testName . replace ( / ' / g, "''" ) ;
113
+ }
114
+
115
+ launchConfig . args . push ( "-TestName" , `'${ testName } '` ) ;
116
+ }
117
+
114
118
return launchConfig ;
115
119
}
116
120
0 commit comments