Skip to content

Commit

Permalink
Add configuration.Output.ShowStartMarkers support (fixes pester#2583).
Browse files Browse the repository at this point in the history
Allow displaying an indication when each test starts:
[|] Test name...
  • Loading branch information
davidmatson committed Jan 22, 2025
1 parent 856f2be commit 858fdbe
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/csharp/Pester/OutputConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class OutputConfiguration : ConfigurationSection
{
private StringOption _verbosity;
private StringOption _stackTraceVerbosity;
private BoolOption _showStartMarkers;
private StringOption _ciFormat;
private StringOption _ciLogLevel;
private StringOption _renderMode;
Expand All @@ -40,6 +41,7 @@ public OutputConfiguration(IDictionary configuration) : this()
{
configuration.AssignObjectIfNotNull<string>(nameof(Verbosity), v => Verbosity = v);
configuration.AssignObjectIfNotNull<string>(nameof(StackTraceVerbosity), v => StackTraceVerbosity = v);
configuration.AssignValueIfNotNull<bool>(nameof(ShowStartMarkers), v => ShowStartMarkers = v);
configuration.AssignObjectIfNotNull<string>(nameof(CIFormat), v => CIFormat = v);
configuration.AssignObjectIfNotNull<string>(nameof(CILogLevel), v => CILogLevel = v);
configuration.AssignObjectIfNotNull<string>(nameof(RenderMode), v => RenderMode = v);
Expand All @@ -50,6 +52,7 @@ public OutputConfiguration() : base("Options to customize the console output gen
{
Verbosity = new StringOption("The verbosity of output, options are None, Normal, Detailed and Diagnostic.", "Normal");
StackTraceVerbosity = new StringOption("The verbosity of stacktrace output, options are None, FirstLine, Filtered and Full.", "Filtered");
ShowStartMarkers = new BoolOption("Write an indication when each test starts.", false);
CIFormat = new StringOption("The CI format of error output in build logs, options are None, Auto, AzureDevops and GithubActions.", "Auto");
CILogLevel = new StringOption("The CI log level in build logs, options are Error and Warning.", "Error");
RenderMode = new StringOption("The mode used to render console output, options are Auto, Ansi, ConsoleColor and Plaintext.", "Auto");
Expand Down Expand Up @@ -87,6 +90,22 @@ public StringOption StackTraceVerbosity
}
}

public BoolOption ShowStartMarkers
{
get { return _showStartMarkers; }
set
{
if (_showStartMarkers == null)
{
_showStartMarkers = value;
}
else
{
_showStartMarkers = new BoolOption(_showStartMarkers, value.Value);
}
}
}

public StringOption CIFormat
{
get { return _ciFormat; }
Expand Down
4 changes: 4 additions & 0 deletions src/en-US/about_PesterConfiguration.help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ SECTIONS AND OPTIONS
Type: string
Default value: 'Filtered'

ShowStartMarkers: Write an indication when each test starts.
Type: bool
Default value: $false

CIFormat: The CI format of error output in build logs, options are None, Auto, AzureDevops and GithubActions.
Type: string
Default value: 'Auto'
Expand Down
14 changes: 12 additions & 2 deletions src/functions/Output.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,20 @@ function Get-WriteScreenPlugin ($Verbosity) {
if ($PesterPreference.Output.Verbosity.Value -in 'Detailed', 'Diagnostic') {
$p.EachTestSetupStart = {
param ($Context)

# we are currently in scope of describe so $Test is hardtyped and conflicts
$_test = $Context.Test

# we postponed writing the Describe / Context to grab the Expanded name, because that is done
# during execution to get all the variables in scope, if we are the first test then write it
if ($Context.Test.First) {
Write-BlockToScreen $Context.Test.Block
if ($_test.First) {
Write-BlockToScreen $_test.Block
}

if ($PesterPreference.Output.ShowStartMarkers.Value) {
$level = $_test.Path.Count
$margin = $ReportStrings.Margin * ($level)
Write-PesterHostMessage -ForegroundColor $ReportTheme.Information "$margin[|] $($_test.ExpandedName)..."
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tst/Pester.RSpec.Configuration.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ i -PassThru:$PassThru {
[PesterConfiguration]::Default.Output.StackTraceVerbosity.Value | Verify-Equal Filtered
}

t "Output.ShowStartMarkers is `$false" {
[PesterConfiguration]::Default.Output.ShowStartMarkers.Value | Verify-False
}

t "Output.CIFormat is Auto" {
[PesterConfiguration]::Default.Output.CIFormat.Value | Verify-Equal Auto
}
Expand Down
43 changes: 43 additions & 0 deletions tst/Pester.RSpec.Output.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,49 @@ i -PassThru:$PassThru {
@($describeFailing).Count | Verify-Equal 1
@($contextFailing).Count | Verify-Equal 1
}

t 'All start markers are output when ShowStartMarkers is enabled' {
$sb = {
$PesterPreference = [PesterConfiguration]::Default
$PesterPreference.Output.Verbosity = 'Detailed'
$PesterPreference.Output.ShowStartMarkers = $true
$PesterPreference.Output.CIFormat = 'None'
$PesterPreference.Output.RenderMode = 'ConsoleColor'

$container = New-PesterContainer -ScriptBlock {
Describe 'd1' {
Context 'c1' {
It 'i1' {
1 | Should -Be 1
}

It 'i2' {
1 | Should -Be 1
}
}

Context 'c2' {
It 'i3' {
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

$i1Start = $output | Select-String -Pattern '\[\|\] i1\.\.\.$'
@($i1Start).Count | Verify-Equal 1
$i2Start = $output | Select-String -Pattern '\[\|\] i2\.\.\.$'
@($i2Start).Count | Verify-Equal 1
$i3Start = $output | Select-String -Pattern '\[\|\] i3\.\.\.$'
@($i3Start).Count | Verify-Equal 1
}
}

b 'Output for data-driven blocks' {
Expand Down

0 comments on commit 858fdbe

Please sign in to comment.