Skip to content

Commit d08debe

Browse files
authored
Fix container name in ScriptBlock BeforeAll failures (fixes #2636). (#2637)
* Fix container name in ScriptBlock BeforeAll failures (fixes #2636). * Update test given new output.
1 parent 5a1bd5b commit d08debe

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/functions/Output.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
569569
param ($Context)
570570

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

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

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

597597
# this won't work skipping the whole file when all it's tests are skipped is not a feature yet in 5.0.0
598598
if ($Context.Result.Skip) {
599-
Write-PesterHostMessage -ForegroundColor $ReportTheme.Skipped "[!] $($Context.Result.Item)" -NoNewLine
599+
Write-PesterHostMessage -ForegroundColor $ReportTheme.Skipped "[!] $($Context.Result.Name)" -NoNewLine
600600
Write-PesterHostMessage -ForegroundColor $ReportTheme.SkippedTime " $humanTime"
601601
}
602602
}

tst/Pester.RSpec.InNewProcess.ts.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ i -PassThru:$PassThru {
384384
$ps.HadErrors | Verify-False
385385
$res.PassedCount | Verify-Equal 1
386386
# Information-stream introduced in PSv5 for Write-Host output
387-
if ($PSVersionTable.PSVersion.Major -ge 5) { $ps.Streams.Information -match 'Describe' | Verify-NotNull }
387+
if ($PSVersionTable.PSVersion.Major -ge 5) { $ps.Streams.Information -match '<ScriptBlock>' | Verify-NotNull }
388388
}
389389
finally {
390390
$ps.Dispose()

tst/Pester.RSpec.Output.ts.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,34 @@ i -PassThru:$PassThru {
250250
}
251251
}
252252

253+
b 'Output for container names' {
254+
t 'Script Block container names are output when BeforeAll fails' {
255+
$sb = {
256+
$PesterPreference = [PesterConfiguration]::Default
257+
$PesterPreference.Output.Verbosity = 'Detailed'
258+
$PesterPreference.Output.RenderMode = 'ConsoleColor'
259+
260+
$container = New-PesterContainer -ScriptBlock {
261+
BeforeAll {
262+
throw 'bad error'
263+
}
264+
Describe 'd1' {
265+
It 'i1' {
266+
1 | Should -Be 1
267+
}
268+
}
269+
}
270+
Invoke-Pester -Container $container
271+
}
272+
273+
$output = Invoke-InNewProcess $sb
274+
$null, $run = $output -join "`n" -split 'Running tests.'
275+
$run | Write-Host
276+
277+
$run | Verify-Like '*[-]*<ScriptBlock>* failed with:*'
278+
}
279+
}
280+
253281
b 'Write-PesterHostMessage' {
254282
t 'Ansi output includes colors when set and always reset' {
255283
$sb = {

0 commit comments

Comments
 (0)