Skip to content

Commit

Permalink
Update output for Discovery and Filter (#1969)
Browse files Browse the repository at this point in the history
* Remove Filter messages from Diagnostic-output

* remove repeating active tag filter message

* removed verebose discovery output in detailed

* add total tests to be executed message

* fix removed BOM

* fix runtime changes leaking to advanced config

* force minimum debug level in diagnostic

* update output after review

* update tests
  • Loading branch information
fflaten committed Jun 5, 2021
1 parent 1246ec3 commit 5dc72a9
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 35 deletions.
15 changes: 13 additions & 2 deletions src/Main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,12 @@ function Invoke-Pester {
# preference is inherited in all subsequent calls in this session state
# but we still pass it explicitly where practical
if (-not $hasCallerPreference) {
[PesterConfiguration] $PesterPreference = $Configuration
if ($PSBoundParameters.ContainsKey('Configuration')) {
# Advanced configuration used, merging to get new reference
[PesterConfiguration] $PesterPreference = [PesterConfiguration]::Merge([PesterConfiguration]::Default, $Configuration)
} else {
[PesterConfiguration] $PesterPreference = $Configuration
}
}
elseif ($hasCallerPreference) {
[PesterConfiguration] $PesterPreference = [PesterConfiguration]::Merge($callerPreference, $Configuration)
Expand All @@ -906,8 +911,14 @@ function Invoke-Pester {
}

if ('Diagnostic' -eq $PesterPreference.Output.Verbosity.Value) {
# Enforce the default debug-output as a minimum. This is the key difference between Detailed and Diagnostic
$PesterPreference.Debug.WriteDebugMessages = $true
$PesterPreference.Debug.WriteDebugMessagesFrom = "Discovery", "Skip", "Filter", "Mock", "CodeCoverage"
$missingCategories = foreach ($category in @("Discovery", "Skip", "Mock", "CodeCoverage")) {
if ($PesterPreference.Debug.WriteDebugMessagesFrom.Value -notcontains $category) {
$category
}
}
$PesterPreference.Debug.WriteDebugMessagesFrom = $PesterPreference.Debug.WriteDebugMessagesFrom.Value + @($missingCategories)
}

$plugins +=
Expand Down
2 changes: 1 addition & 1 deletion src/Pester.RSpec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function New-PesterConfiguration {
Default value: $false
WriteDebugMessagesFrom: 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.
Default value: @('Discovery', 'Skip', 'Filter', 'Mock', 'CodeCoverage')
Default value: @('Discovery', 'Skip', 'Mock', 'CodeCoverage')
ShowNavigationMarkers: Write paths after every block and test, for easy navigation in VSCode.
Default value: $false
Expand Down
8 changes: 1 addition & 7 deletions src/Pester.Runtime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,6 @@ function Discover-Test {
Invoke-PluginStep -Plugins $state.Plugin -Step DiscoveryStart -Context @{
BlockContainers = $BlockContainer
Configuration = $state.PluginConfiguration
Filter = $Filter
} -ThrowOnFailure
}

Expand Down Expand Up @@ -1016,6 +1015,7 @@ function Discover-Test {
FocusedTests = $focusedTests
Duration = $totalDiscoveryDuration.Elapsed
Configuration = $state.PluginConfiguration
Filter = $Filter
} -ThrowOnFailure
}

Expand Down Expand Up @@ -1705,9 +1705,6 @@ function Test-ShouldRun {
# item is excluded when any of the exclude tags match
$tagFilter = $Filter.ExcludeTag
if ($tagFilter -and 0 -ne $tagFilter.Count) {
if ($PesterPreference.Debug.WriteDebugMessages.Value) {
Write-PesterDebugMessage -Scope Filter "($fullDottedPath) There is '$($tagFilter -join ", ")' exclude tag filter."
}
foreach ($f in $tagFilter) {
foreach ($t in $Item.Tag) {
if ($t -like $f) {
Expand Down Expand Up @@ -1768,9 +1765,6 @@ function Test-ShouldRun {
# test is included when it has tags and the any of the tags match
$tagFilter = $Filter.Tag
if ($tagFilter -and 0 -ne $tagFilter.Count) {
if ($PesterPreference.Debug.WriteDebugMessages.Value) {
Write-PesterDebugMessage -Scope Filter "($fullDottedPath) There is '$($tagFilter -join ", ")' include tag filter."
}
$anyIncludeFilters = $true
if ($null -eq $Item.Tag -or 0 -eq $Item.Tag) {
if ($PesterPreference.Debug.WriteDebugMessages.Value) {
Expand Down
2 changes: 1 addition & 1 deletion src/csharp/Pester/DebugConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DebugConfiguration() : base("Debug configuration for Pester. ⚠ Use at y
{
ShowFullErrors = new BoolOption("Show full errors including Pester internal stack.", false);
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", "Filter", "Mock", "CodeCoverage" });
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);
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 Down
42 changes: 20 additions & 22 deletions src/functions/Output.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -493,23 +493,6 @@ function Get-WriteScreenPlugin ($Verbosity) {
param ($Context)

& $SafeCommands["Write-Host"] -ForegroundColor Magenta "`nStarting discovery in $(@($Context.BlockContainers).Length) files."

if ($PesterPreference.Output.Verbosity.Value -in 'Detailed', 'Diagnostic') {
$activeFilters = $Context.Filter.psobject.Properties | & $SafeCommands['Where-Object'] { $_.Value }
if ($null -ne $activeFilters) {
foreach ($aFilter in $activeFilters) {
# Assuming only StringArrayOption filter-types. Might break in the future.
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Filter '$($aFilter.Name)' set to ('$($aFilter.Value -join "', '")')."
}
}
}
}

if ($PesterPreference.Output.Verbosity.Value -in 'Detailed', 'Diagnostic') {
$p.ContainerDiscoveryStart = {
param ($Context)
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Discovering in $($Context.BlockContainer.Item)."
}
}

$p.ContainerDiscoveryEnd = {
Expand All @@ -529,10 +512,6 @@ function Get-WriteScreenPlugin ($Verbosity) {
& $SafeCommands["Write-Host"] -ForegroundColor Red "[-] Discovery in $($path) failed with:"
Write-ErrorToScreen $Context.Block.ErrorRecord
}
elseif ($PesterPreference.Output.Verbosity.Value -in 'Detailed', 'Diagnostic') {
# todo: this is very very slow because of View-flat
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Found $(@(View-Flat -Block $Context.Block).Count) tests. $(ConvertTo-HumanTime $Context.Duration)"
}
}

$p.DiscoveryEnd = {
Expand All @@ -544,7 +523,26 @@ function Get-WriteScreenPlugin ($Verbosity) {
# }

# . Found $count$(if(1 -eq $count) { " test" } else { " tests" })
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Discovery finished in $(ConvertTo-HumanTime $Context.Duration)."

$discoveredTests = @(View-Flat -Block $Context.BlockContainers)
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Discovery found $($discoveredTests.Count) tests in $(ConvertTo-HumanTime $Context.Duration)."

if ($PesterPreference.Output.Verbosity.Value -in 'Detailed', 'Diagnostic') {
$activeFilters = $Context.Filter.psobject.Properties | & $SafeCommands['Where-Object'] { $_.Value }
if ($null -ne $activeFilters) {
foreach ($aFilter in $activeFilters) {
# Assuming only StringArrayOption filter-types. Might break in the future.
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Filter '$($aFilter.Name)' set to ('$($aFilter.Value -join "', '")')."
}

$testsToRun = 0
foreach ($test in $discoveredTests) {
if ($test.ShouldRun) { $testsToRun++ }
}

& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Filters selected $testsToRun tests to run."
}
}

if ($PesterPreference.Run.SkipRun.Value) {
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "`nTest run was skipped."
Expand Down
23 changes: 23 additions & 0 deletions tst/Pester.RSpec.Configuration.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,29 @@ i -PassThru:$PassThru {
}
}

b "configuration modified at runtime" {
t "changes at runtime doesn't leak to advanced configuration object" {
$c = [PesterConfiguration] @{
Run = @{
ScriptBlock = { }
PassThru = $true
}
Output = @{
Verbosity = 'Diagnostic'
}
Debug = @{
WriteDebugMessagesFrom = 'Something'
}
}

$r = Invoke-Pester -Configuration $c

# Diagnostic modifies Debug.WriteDebugMessagesFrom at runtime
$r.Configuration.Debug.WriteDebugMessagesFrom.Value.Count -gt 1 | Verify-True
'Something' -eq $c.Debug.WriteDebugMessagesFrom.Value | Verify-True
}
}

b "New-PesterConfiguration" {
t "Creates default configuration when no parameters are specified" {
$config = New-PesterConfiguration
Expand Down
4 changes: 2 additions & 2 deletions tst/Pester.RSpec.Output.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ i -PassThru:$PassThru {
}
$output = Invoke-PesterInProcess $sb -Setup $setup
# only print the relevant part of output
$null, $run = $output -join "`n" -split "Discovery finished.*"
$null, $run = $output -join "`n" -split "Running tests."
$run | Write-Host

$describe1 = $output | Select-String -Pattern 'Describing d1\s*$'
Expand Down Expand Up @@ -183,7 +183,7 @@ i -PassThru:$PassThru {
}
$output = Invoke-PesterInProcess $sb -Setup $setup
# only print the relevant part of output
$null, $run = $output -join "`n" -split "Discovery finished.*"
$null, $run = $output -join "`n" -split "Running tests."
$run | Write-Host

$describe1 = $output | Select-String -Pattern 'Describing d1 abc\s*$'
Expand Down

0 comments on commit 5dc72a9

Please sign in to comment.