Skip to content

Fix container name in ScriptBlock BeforeAll failures (fixes #2636). by @davidmatson in #2637 (backport to rel/5.x.x) #2644

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

Open
wants to merge 2 commits into
base: rel/5.x.x
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/functions/Output.ps1
Original file line number Diff line number Diff line change
@@ -652,7 +652,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
param ($Context)

if ($Context.Result.ErrorRecord.Count -gt 0) {
$errorHeader = "[-] $($Context.Result.Item) failed with:"
$errorHeader = "[-] $($Context.Result.Name) failed with:"

$formatErrorParams = @{
Err = $Context.Result.ErrorRecord
@@ -673,13 +673,13 @@ function Get-WriteScreenPlugin ($Verbosity) {
$humanTime = "$(Get-HumanTime ($Context.Result.Duration)) ($(Get-HumanTime $Context.Result.UserDuration)|$(Get-HumanTime $Context.Result.FrameworkDuration))"

if ($Context.Result.Passed) {
Write-PesterHostMessage -ForegroundColor $ReportTheme.Pass "[+] $($Context.Result.Item)" -NoNewLine
Write-PesterHostMessage -ForegroundColor $ReportTheme.Pass "[+] $($Context.Result.Name)" -NoNewLine
Write-PesterHostMessage -ForegroundColor $ReportTheme.PassTime " $humanTime"
}

# this won't work skipping the whole file when all it's tests are skipped is not a feature yet in 5.0.0
if ($Context.Result.Skip) {
Write-PesterHostMessage -ForegroundColor $ReportTheme.Skipped "[!] $($Context.Result.Item)" -NoNewLine
Write-PesterHostMessage -ForegroundColor $ReportTheme.Skipped "[!] $($Context.Result.Name)" -NoNewLine
Write-PesterHostMessage -ForegroundColor $ReportTheme.SkippedTime " $humanTime"
}
}
2 changes: 1 addition & 1 deletion tst/Pester.RSpec.InNewProcess.ts.ps1
Original file line number Diff line number Diff line change
@@ -384,7 +384,7 @@ i -PassThru:$PassThru {
$ps.HadErrors | Verify-False
$res.PassedCount | Verify-Equal 1
# Information-stream introduced in PSv5 for Write-Host output
if ($PSVersionTable.PSVersion.Major -ge 5) { $ps.Streams.Information -match 'Describe' | Verify-NotNull }
if ($PSVersionTable.PSVersion.Major -ge 5) { $ps.Streams.Information -match '<ScriptBlock>' | Verify-NotNull }
}
finally {
$ps.Dispose()
28 changes: 28 additions & 0 deletions tst/Pester.RSpec.Output.ts.ps1
Original file line number Diff line number Diff line change
@@ -222,6 +222,34 @@ i -PassThru:$PassThru {
}
}

b 'Output for container names' {
t 'Script Block container names are output when BeforeAll fails' {
$sb = {
$PesterPreference = [PesterConfiguration]::Default
$PesterPreference.Output.Verbosity = 'Detailed'
$PesterPreference.Output.RenderMode = 'ConsoleColor'

$container = New-PesterContainer -ScriptBlock {
BeforeAll {
throw 'bad error'
}
Describe 'd1' {
It 'i1' {
1 | Should -Be 1
}
}
}
Invoke-Pester -Container $container
}

$output = Invoke-InNewProcess $sb
$null, $run = $output -join "`n" -split 'Running tests.'
$run | Write-Host

$run | Verify-Like '*[-]*<ScriptBlock>* failed with:*'
}
}

b 'Write-PesterHostMessage' {
t 'Ansi output includes colors when set and always reset' {
$sb = {
Loading
Oops, something went wrong.