Skip to content

Commit

Permalink
Add configuration.Debug.ShowStartMarkers support (fixes #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 21, 2025
1 parent 856f2be commit 3da0dd5
Show file tree
Hide file tree
Showing 5 changed files with 40 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
1 change: 1 addition & 0 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ $configuration.Debug.WriteDebugMessagesFrom = 'CodeCoverage'

$configuration.Debug.ShowFullErrors = $false
$configuration.Debug.ShowNavigationMarkers = $false
$configuration.Debug.ShowStartMarkers = $false

if ($null -ne $File -and 0 -lt @($File).Count) {
$configuration.Run.Path = $File
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

0 comments on commit 3da0dd5

Please sign in to comment.