OCram85/DroneHelper
OCram85
/
DroneHelper
Archived
1
0
Fork 0
This repository has been archived on 2023-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
DroneHelper/src/Reports/Format-PesterReport.ps1

75 lines
2.9 KiB
PowerShell

function Format-PesterReport {
<#
.SYNOPSIS
Private helper function used by Write-ResultFile.
#>
[CmdletBinding()]
[OutputType([string])]
param (
[Parameter(Mandatory = $true)]
[PSCustomObject]$InputObject,
[Parameter(Mandatory = $false)]
[ValidateSet('Normal', 'Detailed')]
[string]$Verbosity = 'Normal'
)
begin {
}
process {
$Output = @()
$Output += "| Result | Test | Duration |"
$Output += "| :----: | :--- | -------: |"
foreach ($Result in $InputObject.Tests) {
switch ($Result.Result) {
'Passed' {
if ($Verbosity -eq 'Detailed') {
$RawString = "| :heavy_check_mark: | ``{0}`` | *{1}ms* |"
$Output += $RawString -f $Result.ExpandedPath, $Result.UserDuration.Milliseconds
}
}
'Failed' {
$RawString = "| :heavy_exclamation_mark: | ``{0}`` | *{1}ms* |"
$Output += $RawString -f $Result.ExpandedPath, $Result.UserDuration.Milliseconds
$Parsed = $Result.ErrorRecord.Exception.Message -split "`n" | Select-Object -First 1
$Output += "| :fire: | **{0}** | :fire: |" -f $Parsed
}
'NotRun' {
$RawString = "| :trident: | ``{0}`` | *n/a* |"
$Output += $RawString -f $Result.ExpandedPath
}
Default {
$RawString = "| :warning: | ``{0}`` | *{1}ms* |"
$Output += $RawString -f $Result.ExpandedPath, $Result.UserDuration.Milliseconds
}
}
}
$Output += [Environment]::NewLine
# Writing test result summary
$Output += @(
':test_tube: **{0}** Total Tests (' -f $InputObject.TotalCount +
':heavy_check_mark: ``{0} Passed`` :white_small_square:' -f $InputObject.PassedCount +
':trident: ``{0} Skipped / NotRun`` :white_small_square: ' -f (
$InputObject.SkippedCount + $InputObject.NotRunCount
) +
':warning: ``Unknown`` :white_small_square: ' +
':heavy_exclamation_mark: ``{0} Failed``)' -f $InputObject.FailedCount
)
# Writing code coverage summary
# Covered 37,38% / 75%. 610 analyzed Commands in 26 Files.
$Output += @(
':bookmark_tabs: Covered **{0}%** / ' -f [Math]::Round($InputObject.CodeCoverage.CoveragePercent, 2) +
'{0}%. (' -f $InputObject.CodeCoverage.CoveragePercentTarget +
':bookmark: ``{0} analyzed Commands`` ' -f $InputObject.CodeCoverage.CommandsAnalyzedCount +
':page_facing_up: ``in {0} Files``)' -f $InputObject.CodeCoverage.FilesAnalyzedCount
)
Write-Output $Output
}
end {
}
}