Skip to content

Commit

Permalink
Update reporttheme output to remove hard coded colour names (#1934)
Browse files Browse the repository at this point in the history
* remove hard-coded colors, introduce additional reporttheme

* consolidate discovery reporttheme

* updates to rename report themes, remove commented code as per PR #1752 comments

* update faildetail to red, apply to detailed error message lines

* Update Output.ps1

Remove CoverageWarn     = 'DarkRed' since not currently in use

* merge v5.0 changes

* minor formatting, remove comment

* Update src/functions/Output.ps1

Co-authored-by: Jakub Jareš <me@jakubjares.com>

* revert pester build comment

* update remaining colors

Co-authored-by: Jakub Jareš <me@jakubjares.com>
Co-authored-by: Frode Flaten <3436158+fflaten@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 6, 2021
1 parent 5dc72a9 commit 56131fa
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/functions/Output.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $script:ReportTheme = DATA {
PassTime = 'DarkGray'
Fail = 'Red'
FailTime = 'DarkGray'
FailDetail = 'Red'
Skipped = 'Yellow'
SkippedTime = 'DarkGray'
Pending = 'Gray'
Expand All @@ -57,6 +58,9 @@ $script:ReportTheme = DATA {
Foreground = 'White'
Information = 'DarkGray'
Coverage = 'White'
Discovery = 'Magenta'
Container = 'Magenta'
BlockFail = 'Red'
}
}

Expand Down Expand Up @@ -127,7 +131,7 @@ function Write-PesterStart {
# $message += $ReportStrings.TagMessage -f "$($PesterState.TagFilter)"
# }

& $SafeCommands['Write-Host'] -ForegroundColor Magenta $message
& $SafeCommands['Write-Host'] -ForegroundColor $ReportTheme.Discovery $message
}
}

Expand Down Expand Up @@ -289,8 +293,8 @@ function Write-PesterReport {
& $SafeCommands['Write-Host'] ("Container failed: {0}" -f $RunResult.FailedContainersCount) -Foreground $ReportTheme.Fail
& $SafeCommands['Write-Host'] ($cs -join [Environment]::NewLine) -Foreground $ReportTheme.Fail
}
# & $SafeCommands['Write-Host'] ($ReportStrings.TestsPending -f $RunResult.PendingCount) -Foreground $Pending -NoNewLine
# & $SafeCommands['Write-Host'] ($ReportStrings.TestsInconclusive -f $RunResult.InconclusiveCount) -Foreground $Inconclusive
# & $SafeCommands['Write-Host'] ($ReportStrings.TestsPending -f $RunResult.PendingCount) -Foreground $Pending -NoNewLine
# & $SafeCommands['Write-Host'] ($ReportStrings.TestsInconclusive -f $RunResult.InconclusiveCount) -Foreground $Inconclusive
# }
}

Expand Down Expand Up @@ -492,7 +496,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
$p.DiscoveryStart = {
param ($Context)

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

$p.ContainerDiscoveryEnd = {
Expand All @@ -509,7 +513,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
throw "Container type '$($container.Type)' is not supported."
}

& $SafeCommands["Write-Host"] -ForegroundColor Red "[-] Discovery in $($path) failed with:"
& $SafeCommands["Write-Host"] -ForegroundColor $ReportTheme.Fail "[-] Discovery in $($path) failed with:"
Write-ErrorToScreen $Context.Block.ErrorRecord
}
}
Expand All @@ -525,33 +529,33 @@ function Get-WriteScreenPlugin ($Verbosity) {
# . Found $count$(if(1 -eq $count) { " test" } else { " tests" })

$discoveredTests = @(View-Flat -Block $Context.BlockContainers)
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Discovery found $($discoveredTests.Count) tests in $(ConvertTo-HumanTime $Context.Duration)."
& $SafeCommands["Write-Host"] -ForegroundColor $ReportTheme.Discovery "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 "', '")')."
& $SafeCommands["Write-Host"] -ForegroundColor $ReportTheme.Discovery "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."
& $SafeCommands["Write-Host"] -ForegroundColor $ReportTheme.Discovery "Filters selected $testsToRun tests to run."
}
}

if ($PesterPreference.Run.SkipRun.Value) {
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "`nTest run was skipped."
& $SafeCommands["Write-Host"] -ForegroundColor $ReportTheme.Discovery "`nTest run was skipped."
}
}


$p.RunStart = {
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "Running tests."
& $SafeCommands["Write-Host"] -ForegroundColor $ReportTheme.Container "Running tests."
}

if ($PesterPreference.Output.Verbosity.Value -in 'Detailed', 'Diagnostic') {
Expand All @@ -560,7 +564,7 @@ function Get-WriteScreenPlugin ($Verbosity) {

if ("file" -eq $Context.Block.BlockContainer.Type) {
# write two spaces to separate each file
& $SafeCommands["Write-Host"] -ForegroundColor Magenta "`nRunning tests from '$($Context.Block.BlockContainer.Item)'"
& $SafeCommands["Write-Host"] -ForegroundColor $ReportTheme.Container "`nRunning tests from '$($Context.Block.BlockContainer.Item)'"
}
}
}
Expand Down Expand Up @@ -657,8 +661,8 @@ function Get-WriteScreenPlugin ($Verbosity) {
& $SafeCommands['Write-Host'] -ForegroundColor $ReportTheme.Fail "$margin[-] $out" -NoNewLine
& $SafeCommands['Write-Host'] -ForegroundColor $ReportTheme.FailTime " $humanTime"

& $SafeCommands['Write-Host'] -ForegroundColor $ReportTheme.Fail $($e.DisplayStackTrace -replace '(?m)^', $error_margin)
& $SafeCommands['Write-Host'] -ForegroundColor $ReportTheme.Fail $($e.DisplayErrorMessage -replace '(?m)^', $error_margin)
& $SafeCommands['Write-Host'] -ForegroundColor $ReportTheme.FailDetail $($e.DisplayStackTrace -replace '(?m)^',$error_margin)
& $SafeCommands['Write-Host'] -ForegroundColor $ReportTheme.FailDetail $($e.DisplayErrorMessage -replace '(?m)^',$error_margin)
}

}
Expand Down Expand Up @@ -752,7 +756,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
}

foreach ($e in $Context.Block.ErrorRecord) { ConvertTo-FailureLines $e }
& $SafeCommands['Write-Host'] -ForegroundColor Red "[-] $($Context.Block.FrameworkData.CommandUsed) $($Context.Block.Path -join ".") failed"
& $SafeCommands['Write-Host'] -ForegroundColor $ReportTheme.BlockFail "[-] $($Context.Block.FrameworkData.CommandUsed) $($Context.Block.Path -join ".") failed"
Write-ErrorToScreen $Context.Block.ErrorRecord $error_margin
}

Expand Down Expand Up @@ -780,9 +784,9 @@ function Write-ErrorToScreen {
$out = if ($multipleErrors) {
$c = 0
$(foreach ($e in $Err) {
$isFormattedError = $null -ne $e.DisplayErrorMessage
"[$(($c++))] $(if ($isFormattedError){ $e.DisplayErrorMessage } else { $e.Exception })$(if ($null -ne $e.DisplayStackTrace) {"$([Environment]::NewLine)$($e.DisplayStackTrace)"})"
}) -join [Environment]::NewLine
$isFormattedError = $null -ne $e.DisplayErrorMessage
"[$(($c++))] $(if ($isFormattedError){ $e.DisplayErrorMessage } else { $e.Exception })$(if ($null -ne $e.DisplayStackTrace) {"$([Environment]::NewLine)$($e.DisplayStackTrace)"})"
}) -join [Environment]::NewLine
}
else {
$isFormattedError = $null -ne $Err.DisplayErrorMessage
Expand Down

0 comments on commit 56131fa

Please sign in to comment.