Skip to content

Fix container name display when running non-file types (fixes #2639). by @davidmatson in #2640 (backport to rel/5.x.x) #2645

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 1 commit into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/csharp/Pester/ContainerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static ContainerInfo Create()
return new ContainerInfo();
}

public string Name { get => ToStringConverter.ContainerItemToString(Type, Item); }
private string _type = Constants.File;
public string Type
{
Expand Down
6 changes: 2 additions & 4 deletions src/functions/Output.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,8 @@ function Get-WriteScreenPlugin ($Verbosity) {
$p.ContainerRunStart = {
param ($Context)

if ("file" -eq $Context.Block.BlockContainer.Type) {
# write two spaces to separate each file
Write-PesterHostMessage -ForegroundColor $ReportTheme.Container "`nRunning tests from '$($Context.Block.BlockContainer.Item)'"
}
# write two spaces to separate each container
Write-PesterHostMessage -ForegroundColor $ReportTheme.Container "`nRunning tests from '$($Context.Block.BlockContainer.Name)'"
}
}

Expand Down
28 changes: 28 additions & 0 deletions tst/Pester.RSpec.Output.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,34 @@ i -PassThru:$PassThru {
}
}

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

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

$output = Invoke-InNewProcess $sb
# only print the relevant part of output
$null, $run = $output -join "`n" -split 'Running tests.'
$run | Write-Host

$d1Running = $output | Select-String -Pattern '^Running tests from.*\<ScriptBlock\>.*$'
@($d1Running).Count | Verify-Equal 1
}
}

b 'Output for data-driven blocks' {
t 'Each block generated from dataset is output' {
# we incorrectly shared reference to the same framework data hashtable
Expand Down