Skip to content

Commit

Permalink
Add configuration.Debug.ShowStartMarkers support (fixes #2583). (#2612)
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 authored Feb 20, 2025
1 parent c13b538 commit 3808d3c
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/DebugConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static DebugConfiguration ShallowClone(DebugConfiguration configuration)
WriteDebugMessages = new BoolOption("Write Debug messages to screen.", false);
WriteDebugMessagesFrom = new StringArrayOption("Write Debug messages from a given source, WriteDebugMessages must be set to true for this to work. You can use like wildcards to get messages from multiple sources, as well as * to get everything.", new string[] { "Discovery", "Skip", "Mock", "CodeCoverage" });
ShowNavigationMarkers = new BoolOption("Write paths after every block and test, for easy navigation in VSCode.", false);
ShowStartMarkers = new BoolOption("Write an indication when each test starts.", false);
ReturnRawResultObject = new BoolOption("Returns unfiltered result object, this is for development only. Do not rely on this object for additional properties, non-public properties will be renamed without previous notice.", false);
}

Expand All @@ -45,6 +46,7 @@ public DebugConfiguration(IDictionary configuration) : this()
configuration.AssignValueIfNotNull<bool>(nameof(WriteDebugMessages), v => WriteDebugMessages = v);
configuration.AssignArrayIfNotNull<string>(nameof(WriteDebugMessagesFrom), v => WriteDebugMessagesFrom = v);
configuration.AssignValueIfNotNull<bool>(nameof(ShowNavigationMarkers), v => ShowNavigationMarkers = v);
configuration.AssignValueIfNotNull<bool>(nameof(ShowStartMarkers), v => ShowStartMarkers = v);
configuration.AssignValueIfNotNull<bool>(nameof(ReturnRawResultObject), v => ReturnRawResultObject = v);
}
}
Expand All @@ -53,6 +55,7 @@ public DebugConfiguration(IDictionary configuration) : this()
private BoolOption _writeDebugMessages;
private StringArrayOption _writeDebugMessagesFrom;
private BoolOption _showNavigationMarkers;
private BoolOption _showStartMarkers;
private BoolOption _returnRawResultObject;

public BoolOption ShowFullErrors
Expand Down Expand Up @@ -119,6 +122,22 @@ public BoolOption ShowNavigationMarkers
}
}

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

public BoolOption ReturnRawResultObject
{
get { return _returnRawResultObject; }
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 @@ -182,6 +182,10 @@ SECTIONS AND OPTIONS
Type: bool
Default value: $false

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

ReturnRawResultObject: Returns unfiltered result object, this is for development only. Do not rely on this object for additional properties, non-public properties will be renamed without previous notice.
Type: bool
Default value: $false
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.Debug.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 @@ -160,6 +160,10 @@ i -PassThru:$PassThru {
[PesterConfiguration]::Default.Debug.ShowNavigationMarkers.Value | Verify-False
}

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

t "TestDrive.Enabled is `$true" {
[PesterConfiguration]::Default.TestDrive.Enabled.Value | Verify-True
}
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.Debug.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 3808d3c

Please sign in to comment.