Skip to content

Commit

Permalink
Merge pull request #2 from edropps/master
Browse files Browse the repository at this point in the history
Added support for skipped and pending pester tests.
  • Loading branch information
Xainey committed Mar 24, 2017
2 parents 5a141f4 + a183e77 commit 8eaa6a1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
36 changes: 32 additions & 4 deletions Invoke-PSTestReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Param(
[double] $Compliance = 0.8,
[string] $ScriptAnalyzerFile = ".\artifacts\ScriptAnalyzerResults.json",
[string] $PesterFile = ".\artifacts\PesterResults.json",
[string] $OutputDir = ".\artifacts"
[string] $OutputDir = ".\artifacts",
[switch] $FailOnSkippedOrPending
)

# HTML Colors
Expand Down Expand Up @@ -74,6 +75,14 @@ foreach($test in $Pester.TestResult)
{
$status = "<span class='label label-success'>Passed</span>"
}
elseif($test.Result -eq "Skipped")
{
$status = "<span class='label label-warning'>Skipped</span>"
}
elseif($test.Result -eq "Pending")
{
$status = "<span class='label label-info'>Pending</span>"
}
else
{
$status = "<span class='label label-danger'>Failed</span>"
Expand Down Expand Up @@ -204,6 +213,25 @@ foreach($file in $FileCoverage.GetEnumerator())

$OverallCoverage = ($Pester.CodeCoverage.NumberOfCommandsExecuted/$Pester.CodeCoverage.NumberOfCommandsAnalyzed)


# Determine Pester overall status
if($Pester.FailedCount -eq 0)
{
# If the switch $FailOnSkippedOrPending is set, any skipped or pending tests will fail the build.
if ($FailOnSkippedOrPending -and ($Pester.PendingCount -ne 0) -and ($Pester.SkippedCount -ne 0) )
{
$PesterPassed = $false
}
else
{
$PesterPassed = $true
}
}
else
{
$PesterPassed = $false
}

# Replace Everything in html template and output report
$Replace = @{
# Custom
Expand All @@ -216,9 +244,9 @@ $Replace = @{
COMMIT_HASH = Get-GitCommitHash -Length 10

# Generated
BUILD_RESULT = if($OverallCoverage -ge $Compliance -and $Pester.FailedCount -eq 0) {"PASSED"} else {"FAILED"}
BUILD_RESULT_COLOR = if($OverallCoverage -ge $Compliance -and $Pester.FailedCount -eq 0) {"panel-success"} else {"panel-danger"}
BUILD_RESULT_ICON = if($OverallCoverage -ge $Compliance -and $Pester.FailedCount -eq 0) {"fa-check"} else {"fa-times"}
BUILD_RESULT = if($OverallCoverage -ge $Compliance -and $PesterPassed) {"PASSED"} else {"FAILED"}
BUILD_RESULT_COLOR = if($OverallCoverage -ge $Compliance -and$PesterPassed) {"panel-success"} else {"panel-danger"}
BUILD_RESULT_ICON = if($OverallCoverage -ge $Compliance -and $PesterPassed) {"fa-check"} else {"fa-times"}

TEST_TABLE = $TestResultsTable
FILES_TESTED_TABLE = $FilesTestedTable
Expand Down
13 changes: 11 additions & 2 deletions lib/TestReport.htm
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ <h3 class="panel-title"><i class="fa fa-eye" aria-hidden="true"></i> Code Analys
<div class="col-xs-6 col-sm-8">
<h2 class="sub-header" id="tests">
<i class="fa fa-file-code-o" aria-hidden="true"></i> Pester Tests
<span class="badge">{PASSED_COUNT} passed</span><span class="badge">{FAILED_COUNT} failed</span>
<span class="badge">{PASSED_COUNT} passed</span>
<span class="badge">{FAILED_COUNT} failed</span>
<span class="badge">{SKIPPED_COUNT} skipped</span>
<span class="badge">{PENDING_COUNT} pending</span>
</h2>
<table class="table table-striped">
<thead>
Expand Down Expand Up @@ -320,17 +323,23 @@ <h2 class="sub-header" id="coverage">
labels: [
"Pass",
"Fail",
"Skipped",
"Pending"
],
datasets: [
{
data: [{PASSED_COUNT}, {FAILED_COUNT}],
data: [{PASSED_COUNT}, {FAILED_COUNT},{SKIPPED_COUNT},{PENDING_COUNT}],
backgroundColor: [
"#5cb85c",
"#FF6384",
"#f0ad4e",
"#5bc0de",
],
hoverBackgroundColor: [
"#5cb85c",
"#FF6384",
"#f0ad4e",
"#5bc0de",
]
}]
};
Expand Down

0 comments on commit 8eaa6a1

Please sign in to comment.