From 3da0dd5f20f02d4900e1b52ae5a36d20644ea412 Mon Sep 17 00:00:00 2001 From: David Matson Date: Tue, 21 Jan 2025 15:46:06 -0800 Subject: [PATCH] Add configuration.Debug.ShowStartMarkers support (fixes #2583). Allow displaying an indication when each test starts: [|] Test name... --- src/csharp/Pester/DebugConfiguration.cs | 19 +++++++++++++++++++ src/en-US/about_PesterConfiguration.help.txt | 4 ++++ src/functions/Output.ps1 | 14 ++++++++++++-- test.ps1 | 1 + tst/Pester.RSpec.Configuration.ts.ps1 | 4 ++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/csharp/Pester/DebugConfiguration.cs b/src/csharp/Pester/DebugConfiguration.cs index 8497bd600..5ae6f649c 100644 --- a/src/csharp/Pester/DebugConfiguration.cs +++ b/src/csharp/Pester/DebugConfiguration.cs @@ -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); } @@ -45,6 +46,7 @@ public DebugConfiguration(IDictionary configuration) : this() configuration.AssignValueIfNotNull(nameof(WriteDebugMessages), v => WriteDebugMessages = v); configuration.AssignArrayIfNotNull(nameof(WriteDebugMessagesFrom), v => WriteDebugMessagesFrom = v); configuration.AssignValueIfNotNull(nameof(ShowNavigationMarkers), v => ShowNavigationMarkers = v); + configuration.AssignValueIfNotNull(nameof(ShowStartMarkers), v => ShowStartMarkers = v); configuration.AssignValueIfNotNull(nameof(ReturnRawResultObject), v => ReturnRawResultObject = v); } } @@ -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 @@ -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; } diff --git a/src/en-US/about_PesterConfiguration.help.txt b/src/en-US/about_PesterConfiguration.help.txt index c00ff5b29..42b6afb71 100644 --- a/src/en-US/about_PesterConfiguration.help.txt +++ b/src/en-US/about_PesterConfiguration.help.txt @@ -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 diff --git a/src/functions/Output.ps1 b/src/functions/Output.ps1 index 5e8c3d0ea..7c63feb7b 100644 --- a/src/functions/Output.ps1 +++ b/src/functions/Output.ps1 @@ -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)..." } } } diff --git a/test.ps1 b/test.ps1 index 553cd698a..1f62f2037 100644 --- a/test.ps1 +++ b/test.ps1 @@ -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 diff --git a/tst/Pester.RSpec.Configuration.ts.ps1 b/tst/Pester.RSpec.Configuration.ts.ps1 index 72f3b754c..b37945939 100644 --- a/tst/Pester.RSpec.Configuration.ts.ps1 +++ b/tst/Pester.RSpec.Configuration.ts.ps1 @@ -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 }