1
- [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSPossibleIncorrectComparisonWithNull' , ' ' , Justification= ' Intentional use to select non null array items' )]
1
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSPossibleIncorrectComparisonWithNull' , ' ' , Justification = ' Intentional use to select non null array items' )]
2
2
[CmdletBinding (DefaultParameterSetName = ' Default' )]
3
3
param (
4
- [Parameter (Position = 0 )]
5
- [string ]$XLFile ,
4
+ [Parameter (Position = 0 )]
5
+ [string ]$XLFile ,
6
6
7
- [Parameter (ParameterSetName = ' Default' , Position = 1 )]
8
- [Alias (' Path' , ' relative_path' )]
9
- [object []]$Script = ' .' ,
7
+ [Parameter (ParameterSetName = ' Default' , Position = 1 )]
8
+ [String ]$Path = ' .' ,
10
9
11
- [Parameter (ParameterSetName = ' Existing' , Mandatory = $true )]
12
- [switch ]
13
- $UseExisting ,
10
+ [Parameter (ParameterSetName = ' Existing' , Mandatory = $true )]
11
+ [switch ]
12
+ $UseExisting ,
14
13
15
- [Parameter (ParameterSetName = ' Default' , Position = 2 )]
16
- [Parameter (ParameterSetName = ' Existing' , Position = 2 , Mandatory = $true )]
17
- [string ]$OutputFile ,
14
+ [Parameter (ParameterSetName = ' Default' , Position = 2 )]
15
+ [Parameter (ParameterSetName = ' Existing' , Position = 2 , Mandatory = $true )]
16
+ [string ]$OutputFile ,
18
17
19
- [Parameter (ParameterSetName = ' Default' )]
20
- [Alias (" Name" )]
21
- [string []]$TestName ,
18
+ [Parameter (ParameterSetName = ' Default' )]
19
+ [Alias (" Name" )]
20
+ [string []]$TestName ,
22
21
23
- [Parameter (ParameterSetName = ' Default' )]
24
- [switch ]$EnableExit ,
22
+ [Parameter (ParameterSetName = ' Default' )]
23
+ [switch ]$EnableExit ,
25
24
26
- [Parameter (ParameterSetName = ' Default' )]
27
- [Alias (' Tags' )]
28
- [string []]$Tag ,
29
- [string []]$ExcludeTag ,
25
+ [Parameter (ParameterSetName = ' Default' )]
26
+ [Alias (' Tags' )]
27
+ [string []]$Tag ,
28
+ [string []]$ExcludeTag ,
30
29
31
- [Parameter (ParameterSetName = ' Default' )]
32
- [switch ]$Strict ,
30
+ [Parameter (ParameterSetName = ' Default' )]
31
+ [switch ]$Strict ,
33
32
34
- [string ]$WorkSheetName = ' PesterResults' ,
35
- [switch ]$append ,
36
- [switch ]$Show
33
+ [string ]$WorkSheetName = ' PesterResults' ,
34
+ [switch ]$append ,
35
+ [switch ]$Show
37
36
)
38
37
39
- $InvokePesterParams = @ {OutputFormat = ' NUnitXml' } + $PSBoundParameters
40
- if (-not $InvokePesterParams [' OutputFile' ]) {
41
- $InvokePesterParams [' OutputFile' ] = Join-Path - ChildPath ' Pester.xml' - Path ([environment ]::GetFolderPath([System.Environment + SpecialFolder ]::MyDocuments))
42
- }
43
- if ($InvokePesterParams [' Show' ] ) {}
44
- if ($InvokePesterParams [' XLFile' ]) {$InvokePesterParams.Remove (' XLFile' )}
45
- else {$XLFile = $InvokePesterParams [' OutputFile' ] -replace ' .xml$' , ' .xlsx' }
38
+ $InvokePesterParams = $PSBoundParameters
39
+
40
+ if ($InvokePesterParams [' XLFile' ]) { $InvokePesterParams.Remove (' XLFile' ) }
41
+ else { $XLFile = $InvokePesterParams [' OutputFile' ] -replace ' .xml$' , ' .xlsx' }
46
42
if (-not $UseExisting ) {
47
- $InvokePesterParams.Remove (' Append' )
48
- $InvokePesterParams.Remove (' UseExisting' )
49
- $InvokePesterParams.Remove (' Show' )
50
- $InvokePesterParams.Remove (' WorkSheetName' )
51
- Invoke-Pester @InvokePesterParams
43
+ $InvokePesterParams.Remove (' Append' ) | Out-Null
44
+ $InvokePesterParams.Remove (' UseExisting' ) | Out-Null
45
+ $InvokePesterParams.Remove (' Show' ) | Out-Null
46
+ $InvokePesterParams.Remove (' WorkSheetName' ) | Out-Null
47
+ $InvokePesterParams.Remove (' OutputFile' ) | Out-Null
48
+ Set-Location $env: ModulePath
49
+ Invoke-Pester @InvokePesterParams - CI - Output Detailed - ErrorAction Continue
52
50
}
53
51
54
- if (-not (Test-Path - Path $InvokePesterParams [' OutputFile' ])) {
55
- throw " Could not output file $ ( $InvokePesterParams [' OutputFile' ]) " ; return
56
- }
52
+ # if (-not (Test-Path -Path $InvokePesterParams['OutputFile'])) {
53
+ # throw "Could not output file $($InvokePesterParams['OutputFile'])"; return
54
+ # }
57
55
58
- $resultXML = ([xml ](Get-Content $InvokePesterParams [ ' OutputFile ' ] )).' test-results'
59
- $startDate = [datetime ]$resultXML.date
60
- $startTime = $resultXML.time
61
- $machine = $resultXML.environment .' machine-name'
62
- # $user = $resultXML.environment.'user-domain' + '\' + $resultXML.environment.user
63
- $os = $resultXML.environment.platform -replace ' \|.*$' , " $ ( $resultXML.environment .' os-version' ) "
56
+ $resultXML = ([xml ](Get-Content - Path ( Join-Path $ env: ModulePath ' testResults.xml ' ) )).' test-results'
57
+ $startDate = [datetime ]$resultXML.date
58
+ $startTime = $resultXML.time
59
+ $machine = $resultXML.environment .' machine-name'
60
+ $user = $resultXML.environment .' user-domain' + ' \' + $resultXML.environment.user
61
+ $os = $resultXML.environment.platform -replace ' \|.*$' , " $ ( $resultXML.environment .' os-version' ) "
64
62
<# hierarchy goes
65
63
root, [date], start [time], [Name] (always "Pester"), test results broken down as [total],[errors],[failures],[not-run] etc.
66
64
Environment (user & machine info)
@@ -80,52 +78,54 @@ $os = $resultXML.environment.platform -replace '\|.*$'," $($resultXML.e
80
78
Test-case [description] - name as rendered for display with <vars> filled in
81
79
#>
82
80
$testResults = foreach ($test in $resultXML .' test-suite' .results.' test-suite' ) {
83
- $testPs1File = $test.name
84
- # Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case
85
- if ($test.results .' test-suite' .results.' test-suite' -ne $null ) {
86
- foreach ($suite in $test.results .' test-suite' ) {
87
- $Describe = $suite.description
88
- foreach ($subsuite in $suite.results .' test-suite' ) {
89
- $Context = $subsuite.description
90
- if ($subsuite.results .' test-suite' .results.' test-case' ) {
91
- $testCases = $subsuite.results .' test-suite' .results.' test-case'
92
- }
93
- else {$testCases = $subsuite.results .' test-case' }
94
- $testCases | ForEach-Object {
95
- New-Object - TypeName psobject - Property ([ordered ]@ {
96
- Machine = $machine ; OS = $os
97
- Date = $startDate ; Time = $startTime
98
- Executed = $ (if ($_.executed -eq ' True' ) {1 })
99
- Success = $ (if ($_.success -eq ' True' ) {1 })
100
- Duration = $_.time
101
- File = $testPs1File ; Group = $Describe
102
- SubGroup = $Context ; Name = ($_.Description -replace ' \s{2,}' , ' ' )
103
- Result = $_.result ; FullDesc = ' =Group&" "&SubGroup&" "&Name' })
104
- }
105
- }
81
+ $testPs1File = $test.name
82
+ # Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case
83
+ if ($test.results .' test-suite' .results.' test-suite' -ne $null ) {
84
+ foreach ($suite in $test.results .' test-suite' ) {
85
+ $Describe = $suite.description
86
+ foreach ($subsuite in $suite.results .' test-suite' ) {
87
+ $Context = $subsuite.description
88
+ if ($subsuite.results .' test-suite' .results.' test-case' ) {
89
+ $testCases = $subsuite.results .' test-suite' .results.' test-case'
106
90
}
107
- }
108
- else {
109
- $test.results .' test-suite' | ForEach-Object {
110
- $Describe = $_.description
111
- $_.results .' test-case' | ForEach-Object {
112
- New-Object - TypeName psobject - Property ([ordered ]@ {
113
- Machine = $machine ; OS = $os
114
- Date = $startDate ; Time = $startTime
115
- Executed = $ (if ($_.executed -eq ' True' ) {1 })
116
- Success = $ (if ($_.success -eq ' True' ) {1 })
117
- Duration = $_.time
118
- File = $testPs1File ; Group = $Describe
119
- SubGroup = $null ; Name = ($_.Description -replace ' \s{2,}' , ' ' )
120
- Result = $_.result ; FullDesc = ' =Group&" "&Test' })
121
- }
91
+ else { $testCases = $subsuite.results .' test-case' }
92
+ $testCases | ForEach-Object {
93
+ New-Object - TypeName psobject - Property ([ordered ]@ {
94
+ Machine = $machine ; OS = $os
95
+ Date = $startDate ; Time = $startTime
96
+ Executed = $ (if ($_.executed -eq ' True' ) { 1 })
97
+ Success = $ (if ($_.success -eq ' True' ) { 1 })
98
+ Duration = $_.time
99
+ File = $testPs1File ; Group = $Describe
100
+ SubGroup = $Context ; Name = ($_.Description -replace ' \s{2,}' , ' ' )
101
+ Result = $_.result ; FullDesc = ' =Group&" "&SubGroup&" "&Name'
102
+ })
122
103
}
104
+ }
105
+ }
106
+ }
107
+ else {
108
+ $test.results .' test-suite' | ForEach-Object {
109
+ $Describe = $_.description
110
+ $_.results .' test-case' | ForEach-Object {
111
+ New-Object - TypeName psobject - Property ([ordered ]@ {
112
+ Machine = $machine ; OS = $os
113
+ Date = $startDate ; Time = $startTime
114
+ Executed = $ (if ($_.executed -eq ' True' ) { 1 })
115
+ Success = $ (if ($_.success -eq ' True' ) { 1 })
116
+ Duration = $_.time
117
+ File = $testPs1File ; Group = $Describe
118
+ SubGroup = $null ; Name = ($_.Description -replace ' \s{2,}' , ' ' )
119
+ Result = $_.result ; FullDesc = ' =Group&" "&Test'
120
+ })
121
+ }
123
122
}
123
+ }
124
124
}
125
- if (-not $testResults ) {Write-Warning ' No Results found' ; return }
125
+ if (-not $testResults ) { Write-Warning ' No Results found' ; return }
126
126
$clearSheet = -not $Append
127
- $excel = $testResults | Export-Excel - Path $xlFile - WorkSheetname $WorkSheetName - ClearSheet:$clearSheet - Append:$append - PassThru - BoldTopRow - FreezeTopRow - AutoSize - AutoFilter - AutoNameRange
128
- $ws = $excel.Workbook.Worksheets [$WorkSheetName ]
127
+ $excel = $testResults | Export-Excel - Path $xlFile - WorkSheetname $WorkSheetName - ClearSheet:$clearSheet - Append:$append - PassThru - BoldTopRow - FreezeTopRow - AutoSize - AutoFilter - AutoNameRange
128
+ $ws = $excel.Workbook.Worksheets [$WorkSheetName ]
129
129
<# Worksheet should look like ..
130
130
|A |B |C D |E |F |G |H |I |J |K |L |M
131
131
1|Machine |OS |Date Time |Executed |Success |Duration |File |Group |SubGroup |Name |Result |FullDescription
@@ -136,7 +136,7 @@ $ws = $excel.Workbook.Worksheets[$WorkSheetName]
136
136
Set-Column - Worksheet $ws - Column 3 - NumberFormat ' Short Date' # -AutoSize
137
137
138
138
# Hide columns E to J (Executed, Success, Duration, File, Group and Subgroup)
139
- (5 .. 10 ) | ForEach-Object {Set-ExcelColumn - Worksheet $ws - Column $_ - Hide }
139
+ (5 .. 10 ) | ForEach-Object { Set-ExcelColumn - Worksheet $ws - Column $_ - Hide }
140
140
141
141
# Use conditional formatting to make Failures red, and Successes green (skipped remains black ) ... and save
142
142
$endRow = $ws.Dimension.End.Row
0 commit comments