-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a 'FailedTestsDetails' property to health reports
- Loading branch information
1 parent
8dcd7be
commit 07ae506
Showing
9 changed files
with
212 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Function New-FailedTestsInfo { | ||
<# | ||
.SYNOPSIS | ||
Creates one or more custom objects of the type : 'PSCodeHealth.Overall.FailedTestsInfo'. | ||
.DESCRIPTION | ||
Creates one or more custom objects of the type : 'PSCodeHealth.Overall.FailedTestsInfo'. | ||
This outputs an object containing key information about each failed test. This information is used in the overall health report. | ||
.PARAMETER TestsResult | ||
To specify the Pester tests result object. | ||
.EXAMPLE | ||
PS C:\> New-FailedTestsInfo -TestsResult $TestsResult | ||
Returns a new custom object of the type 'PSCodeHealth.Overall.FailedTestsInfo' for each failed test in the input $TestsResult. | ||
.OUTPUTS | ||
PSCodeHealth.Overall.FailedTestsInfo | ||
.NOTES | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([PSCustomObject[]])] | ||
Param ( | ||
[Parameter(Position=0, Mandatory)] | ||
[PSCustomObject]$TestsResult | ||
) | ||
$FailedTests = $TestsResult.TestResult.Where({ -not $_.Passed }) | ||
|
||
Foreach ( $FailedTest in $FailedTests ) { | ||
|
||
$SplitStackTrace = $FailedTest.StackTrace -split ':\s' | ||
$File = ($SplitStackTrace[0] -split '\\')[-1] | ||
$Line = ((($SplitStackTrace[1] -split '\n') | Where-Object { $_ -match 'line' }) -split '\s')[-1] | ||
|
||
$ObjectProperties = [ordered]@{ | ||
'File' = $File | ||
'Line' = $Line | ||
'Describe' = $FailedTest.Describe | ||
'TestName' = $FailedTest.Name | ||
'ErrorMessage' = $FailedTest.FailureMessage | ||
} | ||
|
||
$CustomObject = New-Object -TypeName PSObject -Property $ObjectProperties | ||
$CustomObject.psobject.TypeNames.Insert(0, 'PSCodeHealth.Overall.FailedTestsInfo') | ||
$CustomObject | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
$ModuleName = 'PSCodeHealth' | ||
Import-Module "$PSScriptRoot\..\..\..\$ModuleName\$($ModuleName).psd1" -Force | ||
|
||
Describe 'New-FailedTestsInfo' { | ||
InModuleScope $ModuleName { | ||
|
||
$Mocks = ConvertFrom-Json (Get-Content -Path "$($PSScriptRoot)\..\..\TestData\MockObjects.json" -Raw ) | ||
$MockTestsResult = $Mocks.'Invoke-Pester'.'2FailedTests'.Where({ $_ }) | ||
|
||
Context 'The specified test result contains 2 failed tests' { | ||
|
||
$Results = New-FailedTestsInfo -TestsResult $MockTestsResult | ||
|
||
It 'Should return objects of the type [PSCodeHealth.Overall.FailedTestsInfo]' { | ||
Foreach ( $Result in $Results ) { | ||
$Result | Should BeOfType [PSCustomObject] | ||
($Result | Get-Member).TypeName[0] | Should Be 'PSCodeHealth.Overall.FailedTestsInfo' | ||
} | ||
} | ||
It 'Should return 2 objects' { | ||
$Results.Count | Should Be 2 | ||
} | ||
It 'Should return an object with the expected property "File"' { | ||
Foreach ( $Result in $Results ) { | ||
$Result.File | Should Be 'Coveralls.Tests.ps1' | ||
} | ||
} | ||
It 'Should return an object with the expected property "Line"' { | ||
Foreach ( $Result in $Results ) { | ||
$Result.Line | Should BeIn @('97','101') | ||
} | ||
} | ||
It 'Should return an object with the expected property "Describe"' { | ||
Foreach ( $Result in $Results ) { | ||
$Result.Describe | Should BeIn @('MockDescribe','MockDescribe2') | ||
} | ||
} | ||
It 'Should return an object with the expected property "TestName"' { | ||
Foreach ( $Result in $Results ) { | ||
$Result.TestName | Should BeIn @('MockTestName','MockTestName2') | ||
} | ||
} | ||
It 'Should return an object with the expected property "ErrorMessage"' { | ||
Foreach ( $Result in $Results ) { | ||
$Result.ErrorMessage | Should BeIn @('MockFailureMessage','MockFailureMessage2') | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.