Skip to content

Fixed crash when running pester older than 3.4.5 #2888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions InvokePesterStub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,30 @@ $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 = @{
Expand All @@ -116,18 +136,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')) {
Expand Down Expand Up @@ -164,7 +175,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 {
Expand All @@ -177,5 +189,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
}