@@ -18,8 +18,11 @@ export class PesterTestsFeature implements IFeature {
1818
1919 private command : vscode . Disposable ;
2020 private languageClient : LanguageClient ;
21+ private invokePesterStubScriptPath : string ;
2122
2223 constructor ( private sessionManager : SessionManager ) {
24+ this . invokePesterStubScriptPath = path . resolve ( __dirname , "../../../InvokePesterStub.ps1" ) ;
25+
2326 // File context-menu command - Run Pester Tests
2427 this . command = vscode . commands . registerCommand (
2528 "PowerShell.RunPesterTestsFromFile" ,
@@ -35,8 +38,8 @@ export class PesterTestsFeature implements IFeature {
3538 // This command is provided for usage by PowerShellEditorServices (PSES) only
3639 this . command = vscode . commands . registerCommand (
3740 "PowerShell.RunPesterTests" ,
38- ( uriString , runInDebugger , describeBlockName ?) => {
39- this . launchTests ( uriString , runInDebugger , describeBlockName ) ;
41+ ( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ? ) => {
42+ this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber ) ;
4043 } ) ;
4144 }
4245
@@ -51,38 +54,22 @@ export class PesterTestsFeature implements IFeature {
5154 private launchAllTestsInActiveEditor ( launchType : LaunchType ) {
5255 const uriString = vscode . window . activeTextEditor . document . uri . toString ( ) ;
5356 const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
57+ launchConfig . args . push ( "-All" ) ;
5458 this . launch ( launchConfig ) ;
5559 }
5660
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 ) {
6966
7067 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 ) ;
8269 this . launch ( launchConfig ) ;
8370 }
8471
85- private createLaunchConfig ( uriString : string , launchType : LaunchType ) {
72+ private createLaunchConfig ( uriString : string , launchType : LaunchType , testName ?: string , lineNum ?: number ) {
8673 const uri = vscode . Uri . parse ( uriString ) ;
8774 const currentDocument = vscode . window . activeTextEditor . document ;
8875 const settings = Settings . load ( ) ;
@@ -95,12 +82,10 @@ export class PesterTestsFeature implements IFeature {
9582 request : "launch" ,
9683 type : "PowerShell" ,
9784 name : "PowerShell Launch Pester Tests" ,
98- script : "Invoke-Pester" ,
85+ script : this . invokePesterStubScriptPath ,
9986 args : [
100- "-Script " ,
87+ "-ScriptPath " ,
10188 `'${ scriptPath } '` ,
102- "-PesterOption" ,
103- "@{IncludeVSCodeMarker=$true}" ,
10489 ] ,
10590 internalConsoleOptions : "neverOpen" ,
10691 noDebug : ( launchType === LaunchType . Run ) ,
@@ -111,6 +96,19 @@ export class PesterTestsFeature implements IFeature {
11196 : path . dirname ( currentDocument . fileName ) ,
11297 } ;
11398
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+
114112 return launchConfig ;
115113 }
116114
0 commit comments