From 96a17140a0f8c7a68638575b7946414ac4776f71 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 29 May 2020 22:50:20 -0700 Subject: [PATCH 1/2] Support adding OutputPath and run file --- InvokePesterStub.ps1 | 22 +++++++++++++++++++++- src/features/PesterTests.ts | 23 +++++++++++++++++------ src/session.ts | 2 +- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/InvokePesterStub.ps1 b/InvokePesterStub.ps1 index b1bcb75f61..d023c89816 100755 --- a/InvokePesterStub.ps1 +++ b/InvokePesterStub.ps1 @@ -53,7 +53,10 @@ param( [switch] $MinimumVersion5, [Parameter(Mandatory)] - [string] $Output + [string] $Output, + + [Parameter()] + [string] $OutputPath ) $pesterModule = Microsoft.PowerShell.Core\Get-Module Pester @@ -103,6 +106,14 @@ if ($All) { if ("FromPreference" -ne $Output) { $configuration.Add('Output', @{ Verbosity = $Output }) } + + if ($OutputPath) { + $configuration.Add('TestResult', @{ + Enabled = $true + OutputFormat = "NUnit2.5" + OutputPath = $OutputPath + }) + } Pester\Invoke-Pester -Configuration $configuration | Out-Null } elseif ($pesterModule.Version -ge '3.4.5') { @@ -132,6 +143,15 @@ elseif (($LineNumber -match '\d+') -and ($pesterModule.Version -ge '4.6.0')) { if ("FromPreference" -ne $Output) { $configuration.Add('Output', @{ Verbosity = $Output }) } + + if ($OutputPath) { + $configuration.Add('TestResult', @{ + Enabled = $true + OutputFormat = "NUnit2.5" + OutputPath = $OutputPath + }) + } + Pester\Invoke-Pester -Configuration $configuration | Out-Null } else { diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index 24ddf5759f..31cd4815b1 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -38,8 +38,8 @@ export class PesterTestsFeature implements IFeature { // This command is provided for usage by PowerShellEditorServices (PSES) only this.command = vscode.commands.registerCommand( "PowerShell.RunPesterTests", - (uriString, runInDebugger, describeBlockName?, describeBlockLineNumber?) => { - this.launchTests(uriString, runInDebugger, describeBlockName, describeBlockLineNumber); + (uriString, runInDebugger, describeBlockName?, describeBlockLineNumber?, outputPath?) => { + this.launchTests(uriString, runInDebugger, describeBlockName, describeBlockLineNumber, outputPath); }); } @@ -52,7 +52,7 @@ export class PesterTestsFeature implements IFeature { } private launchAllTestsInActiveEditor(launchType: LaunchType, fileUri: vscode.Uri) { - const uriString = fileUri.toString(); + const uriString = (fileUri || vscode.window.activeTextEditor.document.uri).toString(); const launchConfig = this.createLaunchConfig(uriString, launchType); launchConfig.args.push("-All"); this.launch(launchConfig); @@ -62,14 +62,21 @@ export class PesterTestsFeature implements IFeature { uriString: string, runInDebugger: boolean, describeBlockName?: string, - describeBlockLineNumber?: number) { + describeBlockLineNumber?: number, + outputPath?: string) { const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run; - const launchConfig = this.createLaunchConfig(uriString, launchType, describeBlockName, describeBlockLineNumber); + const launchConfig = this.createLaunchConfig(uriString, launchType, describeBlockName, describeBlockLineNumber, outputPath); this.launch(launchConfig); } - private createLaunchConfig(uriString: string, launchType: LaunchType, testName?: string, lineNum?: number) { + private createLaunchConfig( + uriString: string, + launchType: LaunchType, + testName?: string, + lineNum?: number, + outputPath?: string) { + const uri = vscode.Uri.parse(uriString); const currentDocument = vscode.window.activeTextEditor.document; const settings = Settings.load(); @@ -120,6 +127,10 @@ export class PesterTestsFeature implements IFeature { launchConfig.args.push("-Output", `'${settings.pester.outputVerbosity}'`); } + if (outputPath) { + launchConfig.args.push("-OutputPath", `'${outputPath}'`); + } + return launchConfig; } diff --git a/src/session.ts b/src/session.ts index f391eb75cd..dad8410194 100644 --- a/src/session.ts +++ b/src/session.ts @@ -283,7 +283,7 @@ export class SessionManager implements Middleware { const resolvedCodeLens = next(codeLens, token); const resolveFunc = (codeLensToFix: vscode.CodeLens): vscode.CodeLens => { - if (codeLensToFix.command.command === "editor.action.showReferences") { + if (codeLensToFix.command?.command === "editor.action.showReferences") { const oldArgs = codeLensToFix.command.arguments; // Our JSON objects don't get handled correctly by From 4e30b1640f814652821865a87b43491bec22fc07 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Sat, 30 May 2020 21:31:02 -0700 Subject: [PATCH 2/2] refactor all logic --- src/features/PesterTests.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index 31cd4815b1..9dcf01ed13 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -54,7 +54,6 @@ export class PesterTestsFeature implements IFeature { private launchAllTestsInActiveEditor(launchType: LaunchType, fileUri: vscode.Uri) { const uriString = (fileUri || vscode.window.activeTextEditor.document.uri).toString(); const launchConfig = this.createLaunchConfig(uriString, launchType); - launchConfig.args.push("-All"); this.launch(launchConfig); } @@ -105,15 +104,15 @@ export class PesterTestsFeature implements IFeature { if (lineNum) { launchConfig.args.push("-LineNumber", `${lineNum}`); - } - - if (testName) { + } else if (testName) { // Escape single quotes inside double quotes by doubling them up if (testName.includes("'")) { testName = testName.replace(/'/g, "''"); } launchConfig.args.push("-TestName", `'${testName}'`); + } else { + launchConfig.args.push("-All"); } if (!settings.pester.useLegacyCodeLens) {