From 398d95d6fdf307d8bcfe32ab128111850a7c9092 Mon Sep 17 00:00:00 2001 From: Manny Date: Thu, 13 Aug 2020 00:58:59 -0700 Subject: [PATCH 1/3] Fixed crash when running pester older than 3.4.5 Calling Invoke-Pester with the -show param was breaking tests if running a version of pester older than 3.4.5 Moved logic for building spalt to call invoke-pester into a function and only added the show parameter if running pester 3.4.5 or newer --- InvokePesterStub.ps1 | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/InvokePesterStub.ps1 b/InvokePesterStub.ps1 index d023c89816..5d69abcf2f 100755 --- a/InvokePesterStub.ps1 +++ b/InvokePesterStub.ps1 @@ -87,10 +87,29 @@ $pester4Output = switch ($Output) { } if ($MinimumVersion5 -and $pesterModule.Version -lt "5.0.0") { - Write-Warning "Pester 5.0.0 or newer is required because setting PowerShell > Pester: Use Legacy Code Lens is disabled, but Pester $($pesterModule.Version) is loaded. Some of the code lense features might not work as expected." + Write-Warning "Pester 5.0.0 or newer is required because setting PowerShell > Pester: Use Legacy Code Lens is disabled, but Pester $($pesterModule.Version) is loaded. Some of the code lens features might not work as expected." } +function Get-InvokePesterParams { + $invokePesterParams = @{ + Script = $ScriptPath + } + + if ($pesterModule.Version -ge '3.4.0') { + # -PesterOption was introduced before 3.4.0, and VSCodeMarker in 4.0.3-rc, + # but because no-one checks the integrity of this hashtable we can call + # all of the versions down to 3.4.0 like this + $invokePesterParams.Add("PesterOption", @{IncludeVSCodeMarker=$true}) + } + if ($pesterModule.Version -ge '3.4.5') { + # -Show was introduced in 3.4.5 + $invokePesterParams.Add("Show", $pester4Output) + } + + return $invokePesterParams +} + if ($All) { if ($pesterModule.Version -ge '5.0.0') { $configuration = @{ @@ -116,18 +135,9 @@ if ($All) { } Pester\Invoke-Pester -Configuration $configuration | Out-Null } - elseif ($pesterModule.Version -ge '3.4.5') { - # -Show was introduced in 3.4.5 - Pester\Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true} -Show $pester4Output - } - elseif ($pesterModule.Version -ge '3.4.0') { - # -PesterOption was introduced before 3.4.0, and VSCodeMarker in 4.0.3-rc, - # but because no-one checks the integrity of this hashtable we can call all of the versions - # down to 3.4.0 like this - Pester\Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true} - } else { - Pester\Invoke-Pester -Script $ScriptPath + $invokePesterParams = Get-InvokePesterParams + Pester\Invoke-Pester @invokePesterParams } } elseif (($LineNumber -match '\d+') -and ($pesterModule.Version -ge '4.6.0')) { @@ -164,7 +174,8 @@ elseif ($TestName) { throw "Running tests by test name is unsafe. This should not trigger for Pester 5." } else { - Pester\Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true} -TestName $TestName -Show $pester4Output + $invokePesterParams = Get-InvokePesterParams + Pester\Invoke-Pester @invokePesterParams } } else { @@ -177,5 +188,6 @@ else { Write-Warning "The Describe block's TestName cannot be evaluated. EXECUTING ALL TESTS instead." Write-Warning "To avoid this, install Pester >= 4.6.0 or remove any expressions in the TestName." - Pester\Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true} -Show $pester4Output + $invokePesterParams = Get-InvokePesterParams + Pester\Invoke-Pester @invokePesterParams } From 89c813cfc4bfebfffa62553694b4ae37922d7b64 Mon Sep 17 00:00:00 2001 From: EmmanuelPineiro Date: Thu, 13 Aug 2020 09:06:49 -0700 Subject: [PATCH 2/3] Update InvokePesterStub.ps1 Co-authored-by: Tyler James Leonhardt --- InvokePesterStub.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/InvokePesterStub.ps1 b/InvokePesterStub.ps1 index 5d69abcf2f..59f78d5486 100755 --- a/InvokePesterStub.ps1 +++ b/InvokePesterStub.ps1 @@ -102,6 +102,7 @@ function Get-InvokePesterParams { # all of the versions down to 3.4.0 like this $invokePesterParams.Add("PesterOption", @{IncludeVSCodeMarker=$true}) } + if ($pesterModule.Version -ge '3.4.5') { # -Show was introduced in 3.4.5 $invokePesterParams.Add("Show", $pester4Output) From 1ee8e928a4e16fa793bc6a88ced7035ac1ea84dc Mon Sep 17 00:00:00 2001 From: EmmanuelPineiro Date: Thu, 13 Aug 2020 09:06:58 -0700 Subject: [PATCH 3/3] Update InvokePesterStub.ps1 Co-authored-by: Tyler James Leonhardt --- InvokePesterStub.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvokePesterStub.ps1 b/InvokePesterStub.ps1 index 59f78d5486..8f7eb94fd5 100755 --- a/InvokePesterStub.ps1 +++ b/InvokePesterStub.ps1 @@ -100,7 +100,7 @@ function Get-InvokePesterParams { # -PesterOption was introduced before 3.4.0, and VSCodeMarker in 4.0.3-rc, # but because no-one checks the integrity of this hashtable we can call # all of the versions down to 3.4.0 like this - $invokePesterParams.Add("PesterOption", @{IncludeVSCodeMarker=$true}) + $invokePesterParams.Add("PesterOption", @{ IncludeVSCodeMarker = $true }) } if ($pesterModule.Version -ge '3.4.5') {