From d3b291026a8d457b9d1cc200138e7d5df0658c67 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 14:56:52 +0100 Subject: [PATCH 01/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20emoj?= =?UTF-8?q?i=20retrieval=20logic=20and=20add=20Get-EmojiByKind=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/1-Simple/Emoji.Tests.ps1 | 34 +++++------------------------ tests/1-Simple/Emoji.ps1 | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 tests/1-Simple/Emoji.ps1 diff --git a/tests/1-Simple/Emoji.Tests.ps1 b/tests/1-Simple/Emoji.Tests.ps1 index 2e6e3b19..20fa0f12 100644 --- a/tests/1-Simple/Emoji.Tests.ps1 +++ b/tests/1-Simple/Emoji.Tests.ps1 @@ -10,39 +10,17 @@ param() BeforeAll { - $script:emojis = @( - @{ Name = 'apple'; Symbol = '🍎'; Kind = 'Fruit' } - @{ Name = 'beaming face with smiling eyes'; Symbol = '😁'; Kind = 'Face' } - @{ Name = 'cactus'; Symbol = '🌵'; Kind = 'Plant' } - @{ Name = 'giraffe'; Symbol = '🦒'; Kind = 'Animal' } - @{ Name = 'pencil'; Symbol = '✏️'; Kind = 'Item' } - @{ Name = 'penguin'; Symbol = '🐧'; Kind = 'Animal' } - @{ Name = 'pensive'; Symbol = '😔'; Kind = 'Face' } - @{ Name = 'slightly smiling face'; Symbol = '🙂'; Kind = 'Face' } - @{ Name = 'smiling face with smiling eyes'; Symbol = '😊'; Kind = 'Face' } - ) | ForEach-Object { [PSCustomObject]$_ } - - function Get-Emoji { - <# - .SYNOPSIS - Get emoji by name. - #> - [CmdletBinding()] - param( - [string]$Name = '*' - ) - $script:emojis | Where-Object Name -Like $Name | ForEach-Object Symbol - } + . $PSCommandPath.Replace('.Tests.ps1', '.ps1') } Describe 'Get-Emoji' { Context 'Lookup by whole name' { It 'Returns 🌵 (cactus)' { - Get-Emoji -Name cactus | Should -Be '🌵' + (Get-Emoji -Name cactus).Symbol | Should -Be '🌵' } It 'Returns 🦒 (giraffe)' { - Get-Emoji -Name giraffe | Should -Be '🦒' + Get-Emoji -Name giraffe -Property Symbol | Should -Be '🦒' } } @@ -52,15 +30,15 @@ Describe 'Get-Emoji' { $penEmojis = Get-Emoji -Name pen* } It 'Returns ✏️ (pencil)' { - $penEmojis | Should -Contain '✏️' + $penEmojis.Symbol | Should -Contain '✏️' } It 'Returns 🐧 (penguin)' { - $penEmojis | Should -Contain '🐧' + $penEmojis.Animal | Should -Contain 'Animal' } It 'Returns 😔 (pensive)' { - $penEmojis | Should -Contain '😔' + $penEmojis.Name | Should -Contain 'pensive' } } diff --git a/tests/1-Simple/Emoji.ps1 b/tests/1-Simple/Emoji.ps1 new file mode 100644 index 00000000..9df3de66 --- /dev/null +++ b/tests/1-Simple/Emoji.ps1 @@ -0,0 +1,40 @@ +$script:emojis = @( + @{ Name = 'apple'; Symbol = '🍎'; Kind = 'Fruit' } + @{ Name = 'beaming face with smiling eyes'; Symbol = '😁'; Kind = 'Face' } + @{ Name = 'cactus'; Symbol = '🌵'; Kind = 'Plant' } + @{ Name = 'giraffe'; Symbol = '🦒'; Kind = 'Animal' } + @{ Name = 'pencil'; Symbol = '✏️'; Kind = 'Item' } + @{ Name = 'penguin'; Symbol = '🐧'; Kind = 'Animal' } + @{ Name = 'pensive'; Symbol = '😔'; Kind = 'Face' } + @{ Name = 'slightly smiling face'; Symbol = '🙂'; Kind = 'Face' } + @{ Name = 'smiling face with smiling eyes'; Symbol = '😊'; Kind = 'Face' } +) | ForEach-Object { [PSCustomObject]$_ } + +function Get-Emoji { + <# + .SYNOPSIS + Get emoji by name. + #> + [CmdletBinding()] + param( + [string] $Name = '*', + [string] $Property + ) + if ($Property) { + $script:emojis | Where-Object Name -Like $Name | ForEach-Object $Property + } else { + $script:emojis | Where-Object Name -Like $Name + } +} + +function Get-EmojiByKind { + <# + .SYNOPSIS + Get emoji by kind. + #> + [CmdletBinding()] + param( + [string] $Kind + ) + $script:emojis | Where-Object Kind -eq $Kind +} From 525c5baaeffd538bf1d59f9941d4547715a377a8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 15:06:47 +0100 Subject: [PATCH 02/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20emoji?= =?UTF-8?q?=20test=20assertions=20to=20use=20correct=20properties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/1-Simple/Emoji.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/1-Simple/Emoji.Tests.ps1 b/tests/1-Simple/Emoji.Tests.ps1 index 20fa0f12..8ca4d811 100644 --- a/tests/1-Simple/Emoji.Tests.ps1 +++ b/tests/1-Simple/Emoji.Tests.ps1 @@ -34,7 +34,7 @@ Describe 'Get-Emoji' { } It 'Returns 🐧 (penguin)' { - $penEmojis.Animal | Should -Contain 'Animal' + $penEmojis.Kind | Should -Contain 'Animal' } It 'Returns 😔 (pensive)' { @@ -48,15 +48,15 @@ Describe 'Get-Emoji' { } It 'Returns 🙂 (slightly smiling face)' { - $smilingEmojis | Should -Contain '🙂' + $smilingEmojis.Symbol | Should -Contain '🙂' } It 'Returns 😁 (beaming face with smiling eyes)' { - $smilingEmojis | Should -Contain '😁' + $smilingEmojis.Kind | Should -Contain 'Face' } It 'Returns 😊 (smiling face with smiling eyes)' { - $smilingEmojis | Should -Contain '😊' + $smilingEmojis.Name | Should -Contain 'smiling face with smiling eyes' } } } From 65ed69b6d2beb8ecb6ff39645aecce990501ab0b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 15:09:48 +0100 Subject: [PATCH 03/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20emoji?= =?UTF-8?q?=20retrieval=20functions=20to=20support=20property=20selection?= =?UTF-8?q?=20and=20add=20Get-EmojiByKind=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/2-Standard/Emoji.Configuration.ps1 | 9 ++++--- tests/2-Standard/Emoji.Tests.ps1 | 32 ++++++++++-------------- tests/2-Standard/Emoji.psm1 | 21 ++++++++++++++-- tests/3-Advanced/Emoji/Emoji.Tests.ps1 | 32 ++++++++++-------------- tests/3-Advanced/Emoji/Emoji.psm1 | 21 ++++++++++++++-- 5 files changed, 70 insertions(+), 45 deletions(-) diff --git a/tests/2-Standard/Emoji.Configuration.ps1 b/tests/2-Standard/Emoji.Configuration.ps1 index d91b1e1b..df621791 100644 --- a/tests/2-Standard/Emoji.Configuration.ps1 +++ b/tests/2-Standard/Emoji.Configuration.ps1 @@ -1,13 +1,16 @@ @{ - Run = @{ + Run = @{ Path = $PSScriptRoot PassThru = $true } - TestResult = @{ + TestResult = @{ Enabled = $true TestSuiteName = 'Standard' } - Output = @{ + CodeCoverage = @{ + Enabled = $true + } + Output = @{ CIFormat = 'Auto' StackTraceVerbosity = 'Filtered' Verbosity = 'Detailed' diff --git a/tests/2-Standard/Emoji.Tests.ps1 b/tests/2-Standard/Emoji.Tests.ps1 index 7e984bc6..8ca4d811 100644 --- a/tests/2-Standard/Emoji.Tests.ps1 +++ b/tests/2-Standard/Emoji.Tests.ps1 @@ -7,62 +7,56 @@ Justification = 'Required for Pester tests' )] [CmdletBinding()] -param( - [Parameter(Mandatory)] - [string] $Path -) +param() -Describe 'Emoji' { - It 'Module is importable' { - { Import-Module -Name $Path } | Should -Not -Throw - } +BeforeAll { + . $PSCommandPath.Replace('.Tests.ps1', '.ps1') } Describe 'Get-Emoji' { Context 'Lookup by whole name' { It 'Returns 🌵 (cactus)' { - Get-Emoji -Name cactus | Should -Be '🌵' + (Get-Emoji -Name cactus).Symbol | Should -Be '🌵' } It 'Returns 🦒 (giraffe)' { - Get-Emoji -Name giraffe | Should -Be '🦒' + Get-Emoji -Name giraffe -Property Symbol | Should -Be '🦒' } } Context 'Lookup by wildcard' { Context 'by prefix' { BeforeAll { - $script:emojis = Get-Emoji -Name pen* + $penEmojis = Get-Emoji -Name pen* } - It 'Returns ✏️ (pencil)' { - $script:emojis | Should -Contain '✏️' + $penEmojis.Symbol | Should -Contain '✏️' } It 'Returns 🐧 (penguin)' { - $script:emojis | Should -Contain '🐧' + $penEmojis.Kind | Should -Contain 'Animal' } It 'Returns 😔 (pensive)' { - $script:emojis | Should -Contain '😔' + $penEmojis.Name | Should -Contain 'pensive' } } Context 'by contains' { BeforeAll { - $script:emojis = Get-Emoji -Name *smiling* + $smilingEmojis = Get-Emoji -Name *smiling* } It 'Returns 🙂 (slightly smiling face)' { - $script:emojis | Should -Contain '🙂' + $smilingEmojis.Symbol | Should -Contain '🙂' } It 'Returns 😁 (beaming face with smiling eyes)' { - $script:emojis | Should -Contain '😁' + $smilingEmojis.Kind | Should -Contain 'Face' } It 'Returns 😊 (smiling face with smiling eyes)' { - $script:emojis | Should -Contain '😊' + $smilingEmojis.Name | Should -Contain 'smiling face with smiling eyes' } } } diff --git a/tests/2-Standard/Emoji.psm1 b/tests/2-Standard/Emoji.psm1 index 12996f98..2929ff24 100644 --- a/tests/2-Standard/Emoji.psm1 +++ b/tests/2-Standard/Emoji.psm1 @@ -17,7 +17,24 @@ function Get-Emoji { #> [CmdletBinding()] param( - [string]$Name = '*' + [string] $Name = '*', + [string] $Property ) - $script:emojis | Where-Object Name -Like $Name | ForEach-Object Symbol + if ($Property) { + $script:emojis | Where-Object Name -Like $Name | ForEach-Object $Property + } else { + $script:emojis | Where-Object Name -Like $Name + } +} + +function Get-EmojiByKind { + <# + .SYNOPSIS + Get emoji by kind. + #> + [CmdletBinding()] + param( + [string] $Kind + ) + $script:emojis | Where-Object Kind -EQ $Kind } diff --git a/tests/3-Advanced/Emoji/Emoji.Tests.ps1 b/tests/3-Advanced/Emoji/Emoji.Tests.ps1 index 7e984bc6..8ca4d811 100644 --- a/tests/3-Advanced/Emoji/Emoji.Tests.ps1 +++ b/tests/3-Advanced/Emoji/Emoji.Tests.ps1 @@ -7,62 +7,56 @@ Justification = 'Required for Pester tests' )] [CmdletBinding()] -param( - [Parameter(Mandatory)] - [string] $Path -) +param() -Describe 'Emoji' { - It 'Module is importable' { - { Import-Module -Name $Path } | Should -Not -Throw - } +BeforeAll { + . $PSCommandPath.Replace('.Tests.ps1', '.ps1') } Describe 'Get-Emoji' { Context 'Lookup by whole name' { It 'Returns 🌵 (cactus)' { - Get-Emoji -Name cactus | Should -Be '🌵' + (Get-Emoji -Name cactus).Symbol | Should -Be '🌵' } It 'Returns 🦒 (giraffe)' { - Get-Emoji -Name giraffe | Should -Be '🦒' + Get-Emoji -Name giraffe -Property Symbol | Should -Be '🦒' } } Context 'Lookup by wildcard' { Context 'by prefix' { BeforeAll { - $script:emojis = Get-Emoji -Name pen* + $penEmojis = Get-Emoji -Name pen* } - It 'Returns ✏️ (pencil)' { - $script:emojis | Should -Contain '✏️' + $penEmojis.Symbol | Should -Contain '✏️' } It 'Returns 🐧 (penguin)' { - $script:emojis | Should -Contain '🐧' + $penEmojis.Kind | Should -Contain 'Animal' } It 'Returns 😔 (pensive)' { - $script:emojis | Should -Contain '😔' + $penEmojis.Name | Should -Contain 'pensive' } } Context 'by contains' { BeforeAll { - $script:emojis = Get-Emoji -Name *smiling* + $smilingEmojis = Get-Emoji -Name *smiling* } It 'Returns 🙂 (slightly smiling face)' { - $script:emojis | Should -Contain '🙂' + $smilingEmojis.Symbol | Should -Contain '🙂' } It 'Returns 😁 (beaming face with smiling eyes)' { - $script:emojis | Should -Contain '😁' + $smilingEmojis.Kind | Should -Contain 'Face' } It 'Returns 😊 (smiling face with smiling eyes)' { - $script:emojis | Should -Contain '😊' + $smilingEmojis.Name | Should -Contain 'smiling face with smiling eyes' } } } diff --git a/tests/3-Advanced/Emoji/Emoji.psm1 b/tests/3-Advanced/Emoji/Emoji.psm1 index 12996f98..2929ff24 100644 --- a/tests/3-Advanced/Emoji/Emoji.psm1 +++ b/tests/3-Advanced/Emoji/Emoji.psm1 @@ -17,7 +17,24 @@ function Get-Emoji { #> [CmdletBinding()] param( - [string]$Name = '*' + [string] $Name = '*', + [string] $Property ) - $script:emojis | Where-Object Name -Like $Name | ForEach-Object Symbol + if ($Property) { + $script:emojis | Where-Object Name -Like $Name | ForEach-Object $Property + } else { + $script:emojis | Where-Object Name -Like $Name + } +} + +function Get-EmojiByKind { + <# + .SYNOPSIS + Get emoji by kind. + #> + [CmdletBinding()] + param( + [string] $Kind + ) + $script:emojis | Where-Object Kind -EQ $Kind } From 4cf5ec079896eead7ca9c46e80bca3d6b7888984 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 15:29:27 +0100 Subject: [PATCH 04/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20emoji?= =?UTF-8?q?=20test=20scripts=20to=20require=20a=20mandatory=20Path=20param?= =?UTF-8?q?eter=20for=20module=20import=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/2-Standard/Emoji.Tests.ps1 | 11 ++++++++--- tests/3-Advanced/Emoji/Emoji.Tests.ps1 | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/2-Standard/Emoji.Tests.ps1 b/tests/2-Standard/Emoji.Tests.ps1 index 8ca4d811..4960cdef 100644 --- a/tests/2-Standard/Emoji.Tests.ps1 +++ b/tests/2-Standard/Emoji.Tests.ps1 @@ -7,10 +7,15 @@ Justification = 'Required for Pester tests' )] [CmdletBinding()] -param() +param( + [Parameter(Mandatory)] + [string] $Path +) -BeforeAll { - . $PSCommandPath.Replace('.Tests.ps1', '.ps1') +Describe 'Emoji' { + It 'Module is importable' { + { Import-Module -Name $Path } | Should -Not -Throw + } } Describe 'Get-Emoji' { diff --git a/tests/3-Advanced/Emoji/Emoji.Tests.ps1 b/tests/3-Advanced/Emoji/Emoji.Tests.ps1 index 8ca4d811..4960cdef 100644 --- a/tests/3-Advanced/Emoji/Emoji.Tests.ps1 +++ b/tests/3-Advanced/Emoji/Emoji.Tests.ps1 @@ -7,10 +7,15 @@ Justification = 'Required for Pester tests' )] [CmdletBinding()] -param() +param( + [Parameter(Mandatory)] + [string] $Path +) -BeforeAll { - . $PSCommandPath.Replace('.Tests.ps1', '.ps1') +Describe 'Emoji' { + It 'Module is importable' { + { Import-Module -Name $Path } | Should -Not -Throw + } } Describe 'Get-Emoji' { From 351bae7e92c5b4e677a69faed9ffbcfd7e7a8d00 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 15:30:27 +0100 Subject: [PATCH 05/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Rename=20Conver?= =?UTF-8?q?t-PesterConfigurationToHashtable=20filter=20to=20ConvertFrom-Pe?= =?UTF-8?q?sterConfiguration=20and=20enhance=20functionality=20to=20suppor?= =?UTF-8?q?t=20output=20as=20hashtable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Helpers.psm1 | 37 ++++++++++++++++++++++++------------- scripts/init.ps1 | 2 +- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 405bc219..308bebe9 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -1,4 +1,4 @@ -$nbsp = [char]0x00A0 +$nbsp = [char]0x00A0 $indent = "$nbsp" * 4 $statusIcon = @{ Passed = '✅' @@ -384,7 +384,7 @@ function New-PesterConfigurationHashtable { $result } -filter Convert-PesterConfigurationToHashtable { +filter ConvertFrom-PesterConfiguration { <# .SYNOPSIS Converts a PesterConfiguration object into a hashtable containing only modified settings. @@ -396,7 +396,7 @@ filter Convert-PesterConfigurationToHashtable { When the -IncludeDefaults switch is provided, it includes settings that have not been modified, outputting their default values. .EXAMPLE - New-PesterConfiguration | Convert-PesterConfigurationToHashtable | Format-Hashtable + New-PesterConfiguration | ConvertFrom-PesterConfiguration -AsHashtable | Format-Hashtable Output: ```powershell @@ -475,7 +475,7 @@ filter Convert-PesterConfigurationToHashtable { .EXAMPLE $config = New-PesterConfiguration $config.Run.PassThru = $true - Convert-PesterConfigurationToHashtable -PesterConfiguration $config -OnlyModified | Format-Hashtable + ConvertFrom-PesterConfiguration -PesterConfiguration $config -OnlyModified -AsHashtable | Format-Hashtable Output: ```powershell @@ -504,33 +504,44 @@ filter Convert-PesterConfigurationToHashtable { # Include default values in the output hashtable. [Parameter()] - [switch] $OnlyModified + [switch] $OnlyModified, + + # Output as a hashtable + [Parameter()] + [switch] $AsHashtable ) # Prepare the output hashtable $result = @{} # Iterate over each top-level category (Run, Filter, etc.) - foreach ($category in $PesterConfiguration.PSObject.Properties.Name) { - $categoryObj = $PesterConfiguration.$category + foreach ($category in $PesterConfiguration.PSObject.Properties) { + $categoryObj = $PesterConfiguration.($category.Name) $subHash = @{} # Iterate over each setting within the category - foreach ($settingName in $categoryObj.PSObject.Properties.Name) { + foreach ($setting in $categoryObj.PSObject.Properties) { if ($OnlyModified) { if ($setting.IsModified) { - $subHash[$settingName] = $setting.Value + $subHash[$setting.Name] = $setting.Value } } else { - $subHash[$settingName] = if ($setting.IsModified) { $setting.Value } else { $setting.Default } + $subHash[$setting.Name] = if ($setting.IsModified) { $setting.Value } else { $setting.Default } } } # Add the category sub-hashtable to the result even if empty, to preserve structure. - $result[$category] = $subHash + if ($AsHashtable) { + $result[$category.Name] = $subHash + } else { + $result[$category.Name] = [pscustomobject]$subHash + } } - return $result + if ($AsHashtable) { + return $result + } + return [PSCustomObject]$result } filter Clear-PesterConfigurationEmptyValue { @@ -853,7 +864,7 @@ filter Set-PesterReportConfigurationSummary { [Pester.Run] $TestResults ) - $configurationHashtable = $TestResults.Configuration | Convert-PesterConfigurationToHashtable | Format-Hashtable + $configurationHashtable = $TestResults.Configuration | ConvertFrom-PesterConfiguration -AsHashtable | Format-Hashtable Details 'Configuration' { CodeBlock 'pwsh' { diff --git a/scripts/init.ps1 b/scripts/init.ps1 index ea7cafb6..09e27edf 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -176,7 +176,7 @@ LogGroup 'Init - Export containers' { Write-Output "Containers from configuration: [$($existingContainers.Count)]" foreach ($existingContainer in $existingContainers) { Write-Output "Processing container [$existingContainer]" - $containers += $existingContainer | Convert-PesterConfigurationToHashtable + $containers += $existingContainer | ConvertTo-Hashtable } } Write-Output "Containers from configuration: [$($containers.Count)]" From e6dcb3034cf415c84510d48c3a4306903f97a369 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 15:36:07 +0100 Subject: [PATCH 06/33] Fix formatting inconsistencies in Helpers.psm1 and Emoji.Configuration.ps1 --- scripts/Helpers.psm1 | 2 +- tests/2-Standard/Emoji.Configuration.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 308bebe9..598facc8 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -1,4 +1,4 @@ -$nbsp = [char]0x00A0 +$nbsp = [char]0x00A0 $indent = "$nbsp" * 4 $statusIcon = @{ Passed = '✅' diff --git a/tests/2-Standard/Emoji.Configuration.ps1 b/tests/2-Standard/Emoji.Configuration.ps1 index df621791..d09052b1 100644 --- a/tests/2-Standard/Emoji.Configuration.ps1 +++ b/tests/2-Standard/Emoji.Configuration.ps1 @@ -8,7 +8,7 @@ TestSuiteName = 'Standard' } CodeCoverage = @{ - Enabled = $true + Enabled = $true } Output = @{ CIFormat = 'Auto' From 93710d96eedeb410bafb2cae5ca5f0652fb4b47c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 15:59:16 +0100 Subject: [PATCH 07/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20ReportAsJ?= =?UTF-8?q?son=20input=20to=20output=20test=20reports=20in=20JSON=20format?= =?UTF-8?q?=20and=20implement=20corresponding=20logic=20in=20main.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + action.yml | 6 ++++++ scripts/main.ps1 | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 0798dc32..cda9dea9 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,7 @@ jobs: | **Input** | **Description** | **Default** | |--------------------------------------|--------------------------------------------------------------------------------------------------------|---------------------------------| | `Path` | Path to where tests are located or a configuration file. | *(none)* | +| `ReportAsJson` | Output generated reports in JSON format in addition to the configured format through Pester. | `true` | | `Run_Path` | Directories/files to be searched for tests. | *(none)* | | `Run_ExcludePath` | Directories/files to exclude from the run. | *(none)* | | `Run_ScriptBlock` | ScriptBlocks containing tests to be executed. | *(none)* | diff --git a/action.yml b/action.yml index 6d621398..5ef6d258 100644 --- a/action.yml +++ b/action.yml @@ -10,6 +10,11 @@ inputs: description: | Path to where tests are located or a configuration file. required: false + ReportAsJson: + description: | + Output generated reports in JSON format in addition to the configured format through Pester. + required: false + default: 'true' Run_Path: description: | Directories to be searched for tests, paths directly to test files, or combination of both. @@ -209,6 +214,7 @@ runs: uses: PSModule/GitHub-Script@v1 env: PSMODULE_INVOKE_PESTER_INPUT_Path: ${{ inputs.Path }} + PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson: ${{ inputs.ReportAsJson }} PSMODULE_INVOKE_PESTER_INPUT_Run_Path: ${{ inputs.Run_Path }} PSMODULE_INVOKE_PESTER_INPUT_Run_ExcludePath: ${{ inputs.Run_ExcludePath }} PSMODULE_INVOKE_PESTER_INPUT_Run_ScriptBlock: ${{ inputs.Run_ScriptBlock }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index fdb99199..a4233d46 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -97,6 +97,13 @@ LogGroup 'Eval - Set outputs' { CodeCoverageEnabled = $testResults.Configuration.CodeCoverage.Enabled.Value CodeCoverageOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value } | Format-List | Out-String + + if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true') { + $outputFolderPath = $testResults.Configuration.TestResult.OutputPath.Value | Split-Path -Parent + $outputFilePath = Join-Path -Path $outputFolderPath -ChildPath 'TestResults.json' + Write-Host "Exporting test results to [$outputFilePath]" + $testResults | ConvertTo-Json -Depth 2 | Out-File -FilePath $outputFilePath + } } LogGroup 'Exit' { From a04ad4fb81b9b25f496f4747833051c562e02d3d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 16:03:53 +0100 Subject: [PATCH 08/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Move=20PSMODULE?= =?UTF-8?q?=5FINVOKE=5FPESTER=5FINPUT=5FReportAsJson=20environment=20varia?= =?UTF-8?q?ble=20to=20the=20correct=20section=20in=20action.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5ef6d258..0f96c9b8 100644 --- a/action.yml +++ b/action.yml @@ -214,7 +214,6 @@ runs: uses: PSModule/GitHub-Script@v1 env: PSMODULE_INVOKE_PESTER_INPUT_Path: ${{ inputs.Path }} - PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson: ${{ inputs.ReportAsJson }} PSMODULE_INVOKE_PESTER_INPUT_Run_Path: ${{ inputs.Run_Path }} PSMODULE_INVOKE_PESTER_INPUT_Run_ExcludePath: ${{ inputs.Run_ExcludePath }} PSMODULE_INVOKE_PESTER_INPUT_Run_ScriptBlock: ${{ inputs.Run_ScriptBlock }} @@ -273,6 +272,8 @@ runs: shell: pwsh continue-on-error: true working-directory: ${{ inputs.WorkingDirectory }} + env: + PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson: ${{ inputs.ReportAsJson }} id: test run: ${{ github.action_path }}/scripts/main.ps1 From 7a7d643782e0066cd9d20f1e1e55e23290cab20f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 16:06:48 +0100 Subject: [PATCH 09/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20JSON?= =?UTF-8?q?=20report=20export=20logic=20to=20include=20test=20result=20con?= =?UTF-8?q?figuration=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a4233d46..24a9c257 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -98,7 +98,7 @@ LogGroup 'Eval - Set outputs' { CodeCoverageOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value } | Format-List | Out-String - if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true') { + if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $outputFolderPath = $testResults.Configuration.TestResult.OutputPath.Value | Split-Path -Parent $outputFilePath = Join-Path -Path $outputFolderPath -ChildPath 'TestResults.json' Write-Host "Exporting test results to [$outputFilePath]" From 829eddd3f6430a8a84131aff3ee7af140ed1ef5f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 16:10:23 +0100 Subject: [PATCH 10/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20TestRe?= =?UTF-8?q?sultOutputPath=20to=20use=20the=20parent=20directory=20of=20the?= =?UTF-8?q?=20output=20path=20in=20main.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 24a9c257..36eadc3b 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -87,7 +87,8 @@ LogGroup 'Eval - Test results summary' { LogGroup 'Eval - Set outputs' { Set-GitHubOutput -Name 'TestSuiteName' -Value $testResults.Configuration.TestResult.TestSuiteName.Value Set-GitHubOutput -Name 'TestResultEnabled' -Value $testResults.Configuration.TestResult.Enabled.Value - Set-GitHubOutput -Name 'TestResultOutputPath' -Value $testResults.Configuration.TestResult.OutputPath.Value + $testResultOutputFolderPath = $testResults.Configuration.TestResult.OutputPath.Value | Split-Path -Parent + Set-GitHubOutput -Name 'TestResultOutputPath' -Value $testResultOutputFolderPath Set-GitHubOutput -Name 'CodeCoverageEnabled' -Value $testResults.Configuration.CodeCoverage.Enabled.Value Set-GitHubOutput -Name 'CodeCoverageOutputPath' -Value $testResults.Configuration.CodeCoverage.OutputPath.Value [pscustomobject]@{ From 60bedd6d673b670e5d03e671ff146d61f275c456 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 16:16:19 +0100 Subject: [PATCH 11/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20output?= =?UTF-8?q?=20paths=20for=20test=20results=20and=20code=20coverage=20repor?= =?UTF-8?q?ts=20to=20use=20dedicated=20directories?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/init.ps1 | 4 ++-- scripts/main.ps1 | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/scripts/init.ps1 b/scripts/init.ps1 index 09e27edf..0bba1f0e 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -223,8 +223,8 @@ LogGroup 'Init - Export containers' { LogGroup 'Init - Export configuration' { $artifactName = $configuration.TestResult.TestSuiteName ?? 'Pester' - $configuration.TestResult.OutputPath = "$pwd/test_reports/$artifactName-TestResult-Report.xml" - $configuration.CodeCoverage.OutputPath = "$pwd/test_reports/$artifactName-CodeCoverage-Report.xml" + $configuration.TestResult.OutputPath = "$pwd/TestResult/$artifactName-TestResult-Report.xml" + $configuration.CodeCoverage.OutputPath = "$pwd/CodeCoverage/$artifactName-CodeCoverage-Report.xml" $configuration.Run.PassThru = $true Format-Hashtable -Hashtable $configuration diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 36eadc3b..f869d577 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -85,19 +85,20 @@ LogGroup 'Eval - Test results summary' { } LogGroup 'Eval - Set outputs' { - Set-GitHubOutput -Name 'TestSuiteName' -Value $testResults.Configuration.TestResult.TestSuiteName.Value - Set-GitHubOutput -Name 'TestResultEnabled' -Value $testResults.Configuration.TestResult.Enabled.Value $testResultOutputFolderPath = $testResults.Configuration.TestResult.OutputPath.Value | Split-Path -Parent - Set-GitHubOutput -Name 'TestResultOutputPath' -Value $testResultOutputFolderPath - Set-GitHubOutput -Name 'CodeCoverageEnabled' -Value $testResults.Configuration.CodeCoverage.Enabled.Value - Set-GitHubOutput -Name 'CodeCoverageOutputPath' -Value $testResults.Configuration.CodeCoverage.OutputPath.Value + $codeCoverageOutputFolderPath = $testResults.Configuration.CodeCoverage.OutputPath.Value | Split-Path -Parent [pscustomobject]@{ TestSuiteName = $testResults.Configuration.TestResult.TestSuiteName.Value TestResultEnabled = $testResults.Configuration.TestResult.Enabled.Value - TestResultOutputPath = $testResults.Configuration.TestResult.OutputPath.Value + TestResultOutputPath = $testResultOutputFolderPath CodeCoverageEnabled = $testResults.Configuration.CodeCoverage.Enabled.Value - CodeCoverageOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value + CodeCoverageOutputPath = $codeCoverageOutputFolderPath } | Format-List | Out-String + Set-GitHubOutput -Name 'TestSuiteName' -Value $testResults.Configuration.TestResult.TestSuiteName.Value + Set-GitHubOutput -Name 'TestResultEnabled' -Value $testResults.Configuration.TestResult.Enabled.Value + Set-GitHubOutput -Name 'TestResultOutputPath' -Value $testResultOutputFolderPath + Set-GitHubOutput -Name 'CodeCoverageEnabled' -Value $testResults.Configuration.CodeCoverage.Enabled.Value + Set-GitHubOutput -Name 'CodeCoverageOutputPath' -Value $codeCoverageOutputFolderPath if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $outputFolderPath = $testResults.Configuration.TestResult.OutputPath.Value | Split-Path -Parent @@ -105,6 +106,13 @@ LogGroup 'Eval - Set outputs' { Write-Host "Exporting test results to [$outputFilePath]" $testResults | ConvertTo-Json -Depth 2 | Out-File -FilePath $outputFilePath } + + if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { + $outputFolderPath = $testResults.Configuration.CodeCoverage.OutputPath.Value | Split-Path -Parent + $outputFilePath = Join-Path -Path $outputFolderPath -ChildPath 'CodeCoverage.json' + Write-Host "Exporting CodeCoverage results to [$outputFilePath]" + $testResults.CodeCoverage | ConvertTo-Json -Depth 100 | Out-File -FilePath $outputFilePath + } } LogGroup 'Exit' { From 5560ccf2e0543dc3ae402e1209b3151062f41f27 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 16:27:27 +0100 Subject: [PATCH 12/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20JSON?= =?UTF-8?q?=20export=20logic=20to=20directly=20replace=20XML=20file=20exte?= =?UTF-8?q?nsion=20and=20improve=20output=20path=20handling=20for=20test?= =?UTF-8?q?=20results=20and=20code=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index f869d577..30ca974a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -101,17 +101,15 @@ LogGroup 'Eval - Set outputs' { Set-GitHubOutput -Name 'CodeCoverageOutputPath' -Value $codeCoverageOutputFolderPath if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { - $outputFolderPath = $testResults.Configuration.TestResult.OutputPath.Value | Split-Path -Parent - $outputFilePath = Join-Path -Path $outputFolderPath -ChildPath 'TestResults.json' - Write-Host "Exporting test results to [$outputFilePath]" - $testResults | ConvertTo-Json -Depth 2 | Out-File -FilePath $outputFilePath + $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' + Write-Host "Exporting test results to [$jsonOutputPath]" + $testResults | ConvertTo-Json -Depth 2 | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { - $outputFolderPath = $testResults.Configuration.CodeCoverage.OutputPath.Value | Split-Path -Parent - $outputFilePath = Join-Path -Path $outputFolderPath -ChildPath 'CodeCoverage.json' - Write-Host "Exporting CodeCoverage results to [$outputFilePath]" - $testResults.CodeCoverage | ConvertTo-Json -Depth 100 | Out-File -FilePath $outputFilePath + $jsonOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value -Replace '\.xml$', '.json' + Write-Host "Exporting code coverage results to [$jsonOutputPath]" + $testResults.CodeCoverage | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath } } From 49c7a8272afbf7d88896a54f5b1a785d8be66583 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 16:33:07 +0100 Subject: [PATCH 13/33] Add retention days for uploaded test results and code coverage reports --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index 0f96c9b8..9fd0fb82 100644 --- a/action.yml +++ b/action.yml @@ -283,6 +283,7 @@ runs: with: name: ${{ steps.test.outputs.TestSuiteName }}-TestResults path: ${{ steps.test.outputs.TestResultOutputPath }} + retention-days: 1 - name: Upload code coverage report - [${{ steps.test.outputs.TestSuiteName }}-CodeCoverage] uses: actions/upload-artifact@v4 @@ -290,6 +291,7 @@ runs: with: name: ${{ steps.test.outputs.TestSuiteName }}-CodeCoverage path: ${{ steps.test.outputs.CodeCoverageOutputPath }} + retention-days: 1 - name: Status shell: pwsh From fb07823456fac545e594604a36819d51e98335e1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 16:34:24 +0100 Subject: [PATCH 14/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20error=20h?= =?UTF-8?q?andling=20for=20missing=20files=20in=20artifact=20uploads=20and?= =?UTF-8?q?=20refactor=20Get-PesterTestTree=20for=20improved=20clarity=20a?= =?UTF-8?q?nd=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index 9fd0fb82..546ac0ac 100644 --- a/action.yml +++ b/action.yml @@ -284,6 +284,7 @@ runs: name: ${{ steps.test.outputs.TestSuiteName }}-TestResults path: ${{ steps.test.outputs.TestResultOutputPath }} retention-days: 1 + if-no-files-found: error - name: Upload code coverage report - [${{ steps.test.outputs.TestSuiteName }}-CodeCoverage] uses: actions/upload-artifact@v4 @@ -292,6 +293,7 @@ runs: name: ${{ steps.test.outputs.TestSuiteName }}-CodeCoverage path: ${{ steps.test.outputs.CodeCoverageOutputPath }} retention-days: 1 + if-no-files-found: error - name: Status shell: pwsh From 8e76510e69f503d73839bddb9af56b9d628bf577 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 17:20:37 +0100 Subject: [PATCH 15/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Replace=20Write?= =?UTF-8?q?-Host=20with=20Write-Output=20for=20exporting=20test=20results?= =?UTF-8?q?=20and=20code=20coverage=20in=20JSON=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 30ca974a..50aaf31d 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -102,13 +102,13 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' - Write-Host "Exporting test results to [$jsonOutputPath]" + Write-Output "Exporting test results to [$jsonOutputPath]" $testResults | ConvertTo-Json -Depth 2 | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value -Replace '\.xml$', '.json' - Write-Host "Exporting code coverage results to [$jsonOutputPath]" + Write-Output "Exporting code coverage results to [$jsonOutputPath]" $testResults.CodeCoverage | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath } } From 6de794630c497507b73c4e20612134875ced8aae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 17:41:36 +0100 Subject: [PATCH 16/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20Conv?= =?UTF-8?q?ertFrom-PesterConfiguration=20to=20improve=20clarity=20and=20st?= =?UTF-8?q?ructure=20by=20simplifying=20variable=20usage=20and=20enhancing?= =?UTF-8?q?=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Helpers.psm1 | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 598facc8..40685f5c 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -1,4 +1,4 @@ -$nbsp = [char]0x00A0 +$nbsp = [char]0x00A0 $indent = "$nbsp" * 4 $statusIcon = @{ Passed = '✅' @@ -516,25 +516,23 @@ filter ConvertFrom-PesterConfiguration { # Iterate over each top-level category (Run, Filter, etc.) foreach ($category in $PesterConfiguration.PSObject.Properties) { - $categoryObj = $PesterConfiguration.($category.Name) + $categoryName = $category.Name + $categoryValue = $category.Value $subHash = @{} # Iterate over each setting within the category - foreach ($setting in $categoryObj.PSObject.Properties) { - if ($OnlyModified) { - if ($setting.IsModified) { - $subHash[$setting.Name] = $setting.Value - } - } else { - $subHash[$setting.Name] = if ($setting.IsModified) { $setting.Value } else { $setting.Default } - } + foreach ($setting in $categoryValue.PSObject.Properties) { + $settingName = $setting.Name + $settingValue = $setting.Value + $settingValue = $settingValue.IsModified ? ($OnlyModified ? $settingValue.Value : $null ) : $settingValue.Default + $subHash[$settingName] = $settingValue } # Add the category sub-hashtable to the result even if empty, to preserve structure. if ($AsHashtable) { - $result[$category.Name] = $subHash + $result[$categoryName] = $subHash } else { - $result[$category.Name] = [pscustomobject]$subHash + $result[$categoryName] = [pscustomobject]$subHash } } From 964d3c81825ddf9db757c94468263149eb9684a6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 17:47:00 +0100 Subject: [PATCH 17/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20Get-?= =?UTF-8?q?PesterTestTree=20to=20improve=20structure=20and=20readability,?= =?UTF-8?q?=20enhancing=20object=20property=20handling=20and=20adding=20ve?= =?UTF-8?q?rbose=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Helpers.psm1 | 66 +++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 40685f5c..6dd25317 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -1,4 +1,4 @@ -$nbsp = [char]0x00A0 +$nbsp = [char]0x00A0 $indent = "$nbsp" * 4 $statusIcon = @{ Passed = '✅' @@ -524,8 +524,9 @@ filter ConvertFrom-PesterConfiguration { foreach ($setting in $categoryValue.PSObject.Properties) { $settingName = $setting.Name $settingValue = $setting.Value - $settingValue = $settingValue.IsModified ? ($OnlyModified ? $settingValue.Value : $null ) : $settingValue.Default + $settingValue = $OnlyModified ? $settingValue.Value : ($settingValue.IsModified ? $settingValue.Value : $settingValue.Default) $subHash[$settingName] = $settingValue + Write-Verbose "[$categoryName] [$settingName] = $settingValue" -Verbose } # Add the category sub-hashtable to the result even if empty, to preserve structure. @@ -654,32 +655,53 @@ filter Get-PesterTestTree { Write-Verbose "Processing object of type: $($InputObject.GetType().Name)" switch ($InputObject.GetType().Name) { 'Run' { - $inputObject | Add-Member -MemberType NoteProperty -Name Depth -Value 0 - $inputObject | Add-Member -MemberType NoteProperty -Name ItemType -Value 'TestSuite' - $inputObject | Add-Member -MemberType NoteProperty -Name Name -Value $($testResults.Configuration.TestResult.TestSuiteName.Value) -Force - $inputObject | Add-Member -MemberType NoteProperty -Name Children -Value $inputObject.Containers - $inputObject - $inputObject.Containers | Get-PesterTestTree + $children = $InputObject.Containers | Get-PesterTestTree + $configuration = $InputObject.Configuration | ConvertTo-Hashtable + [pscustomobject]@{ + Depth = 0 + ItemType = 'TestSuite' + Name = $($InputObject.Configuration.TestResult.TestSuiteName.Value) + Children = $children + Result = $InputObject.Result + FailedCount = $InputObject.FailedCount + FailedBlocksCount = $InputObject.FailedBlocksCount + FailedContainersCount = $InputObject.FailedContainersCount + PassedCount = $InputObject.PassedCount + SkippedCount = $InputObject.SkippedCount + InconclusiveCount = $InputObject.InconclusiveCount + NotRunCount = $InputObject.NotRunCount + TotalCount = $InputObject.TotalCount + Duration = $InputObject.Duration + Executed = $InputObject.Executed + ExecutedAt = $InputObject.ExecutedAt + Version = $InputObject.Version + PSVersion = $InputObject.PSVersion + Plugins = $InputObject.Plugins + PluginConfiguration = $InputObject.PluginConfiguration + PluginData = $InputObject.PluginData + Configuration = $configuration + DiscoveryDuration = $InputObject.DiscoveryDuration + UserDuration = $InputObject.UserDuration + FrameworkDuration = $InputObject.FrameworkDuration + } } 'Container' { - $inputObject | Add-Member -MemberType NoteProperty -Name Depth -Value 1 - $inputObject | Add-Member -MemberType NoteProperty -Name ItemType -Value 'Container' - $inputObject | Add-Member -MemberType NoteProperty -Name Name -Value ((Split-Path $InputObject.Name -Leaf) -replace '.Tests.ps1') -Force - $inputObject | Add-Member -MemberType NoteProperty -Name Children -Value $InputObject.Blocks - $inputObject - $InputObject.Blocks | Get-PesterTestTree + $children = $InputObject.Blocks | Get-PesterTestTree + $InputObject | Add-Member -MemberType NoteProperty -Name Depth -Value 1 + $InputObject | Add-Member -MemberType NoteProperty -Name ItemType -Value 'Container' + $InputObject | Add-Member -MemberType NoteProperty -Name Name -Value ((Split-Path $InputObject.Name -Leaf) -replace '.Tests.ps1') -Force + $InputObject | Add-Member -MemberType NoteProperty -Name Children -Value $InputObject.Blocks } 'Block' { - $inputObject | Add-Member -MemberType NoteProperty -Name Depth -Value ($InputObject.Path.Count + 1) - $inputObject | Add-Member -MemberType NoteProperty -Name Name -Value ($InputObject.ExpandedName) -Force - $inputObject | Add-Member -MemberType NoteProperty -Name Children -Value $InputObject.Order - $inputObject - $InputObject.Order | Get-PesterTestTree + $children = $InputObject.Order | Get-PesterTestTree + $InputObject | Add-Member -MemberType NoteProperty -Name Depth -Value ($InputObject.Path.Count + 1) + $InputObject | Add-Member -MemberType NoteProperty -Name Name -Value ($InputObject.ExpandedName) -Force + $InputObject | Add-Member -MemberType NoteProperty -Name Children -Value $InputObject.Order } 'Test' { - $inputObject | Add-Member -MemberType NoteProperty -Name Depth -Value ($InputObject.Path.Count + 1) - $inputObject | Add-Member -MemberType NoteProperty -Name Name -Value ($InputObject.ExpandedName) -Force - $inputObject + $InputObject | Add-Member -MemberType NoteProperty -Name Depth -Value ($InputObject.Path.Count + 1) + $InputObject | Add-Member -MemberType NoteProperty -Name Name -Value ($InputObject.ExpandedName) -Force + $InputObject } default { Write-Error "Unknown object type: [$($InputObject.GetType().Name)]" From cb1bfd6c92b3751348d011dac2b90b3e5f12d2de Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 18:28:28 +0100 Subject: [PATCH 18/33] Enhance Get-PesterTestTree to support path tracking and improve JSON export depth for test results --- scripts/Helpers.psm1 | 115 +++++++++++++++++++++++++++++++++++++------ scripts/main.ps1 | 2 +- 2 files changed, 100 insertions(+), 17 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 6dd25317..b073603a 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -649,18 +649,26 @@ filter Get-PesterTestTree { Mandatory, ValueFromPipeline )] - [object] $InputObject + [object] $InputObject, + + # Path to this node. + [Parameter()] + [string[]] $Path ) + $children = [System.Collections.Generic.List[object]]::new() Write-Verbose "Processing object of type: $($InputObject.GetType().Name)" switch ($InputObject.GetType().Name) { 'Run' { - $children = $InputObject.Containers | Get-PesterTestTree - $configuration = $InputObject.Configuration | ConvertTo-Hashtable + $Name = $InputObject.Configuration.TestResult.TestSuiteName.Value + $childPath = @($Path, $Name) + $children.Add(($InputObject.Containers | Get-PesterTestTree -Path $childPath)) + $configuration = $InputObject.Configuration | ConvertFrom-PesterConfiguration [pscustomobject]@{ Depth = 0 ItemType = 'TestSuite' - Name = $($InputObject.Configuration.TestResult.TestSuiteName.Value) + Name = $Name + Path = @() Children = $children Result = $InputObject.Result FailedCount = $InputObject.FailedCount @@ -686,22 +694,97 @@ filter Get-PesterTestTree { } } 'Container' { - $children = $InputObject.Blocks | Get-PesterTestTree - $InputObject | Add-Member -MemberType NoteProperty -Name Depth -Value 1 - $InputObject | Add-Member -MemberType NoteProperty -Name ItemType -Value 'Container' - $InputObject | Add-Member -MemberType NoteProperty -Name Name -Value ((Split-Path $InputObject.Name -Leaf) -replace '.Tests.ps1') -Force - $InputObject | Add-Member -MemberType NoteProperty -Name Children -Value $InputObject.Blocks + $Name = (Split-Path $InputObject.Name -Leaf) -replace '.Tests.ps1' + $childPath = @($Path, $Name) + $children.Add(($InputObject.Blocks | Get-PesterTestTree -Path $childPath)) + [pscustomobject]@{ + Depth = 1 + ItemType = 'Container' + Name = $Name + Path = $Path + Children = $children + Result = $InputObject.Result + FailedCount = $InputObject.FailedCount + FailedBlocksCount = $InputObject.FailedBlocksCount + FailedContainersCount = $InputObject.FailedContainersCount + PassedCount = $InputObject.PassedCount + SkippedCount = $InputObject.SkippedCount + InconclusiveCount = $InputObject.InconclusiveCount + NotRunCount = $InputObject.NotRunCount + TotalCount = $InputObject.TotalCount + Duration = $InputObject.Duration + Executed = $InputObject.Executed + ExecutedAt = $InputObject.ExecutedAt + Version = $InputObject.Version + PSVersion = $InputObject.PSVersion + Plugins = $InputObject.Plugins + PluginConfiguration = $InputObject.PluginConfiguration + PluginData = $InputObject.PluginData + DiscoveryDuration = $InputObject.DiscoveryDuration + UserDuration = $InputObject.UserDuration + FrameworkDuration = $InputObject.FrameworkDuration + } } 'Block' { - $children = $InputObject.Order | Get-PesterTestTree - $InputObject | Add-Member -MemberType NoteProperty -Name Depth -Value ($InputObject.Path.Count + 1) - $InputObject | Add-Member -MemberType NoteProperty -Name Name -Value ($InputObject.ExpandedName) -Force - $InputObject | Add-Member -MemberType NoteProperty -Name Children -Value $InputObject.Order + $Name = ($InputObject.ExpandedName) + $childPath = @($Path, $Name) + $children.Add(($InputObject.Order | Get-PesterTestTree -Path $childPath)) + [pscustomobject]@{ + Depth = ($InputObject.Path.Count + 1) + ItemType = $InputObject.ItemType + Name = $Name + Path = $Path + Children = $children + Result = $InputObject.Result + FailedCount = $InputObject.FailedCount + FailedBlocksCount = $InputObject.FailedBlocksCount + FailedContainersCount = $InputObject.FailedContainersCount + PassedCount = $InputObject.PassedCount + SkippedCount = $InputObject.SkippedCount + InconclusiveCount = $InputObject.InconclusiveCount + NotRunCount = $InputObject.NotRunCount + TotalCount = $InputObject.TotalCount + Duration = $InputObject.Duration + Executed = $InputObject.Executed + ExecutedAt = $InputObject.ExecutedAt + Version = $InputObject.Version + PSVersion = $InputObject.PSVersion + Plugins = $InputObject.Plugins + PluginConfiguration = $InputObject.PluginConfiguration + PluginData = $InputObject.PluginData + DiscoveryDuration = $InputObject.DiscoveryDuration + UserDuration = $InputObject.UserDuration + FrameworkDuration = $InputObject.FrameworkDuration + } } 'Test' { - $InputObject | Add-Member -MemberType NoteProperty -Name Depth -Value ($InputObject.Path.Count + 1) - $InputObject | Add-Member -MemberType NoteProperty -Name Name -Value ($InputObject.ExpandedName) -Force - $InputObject + $Name = ($InputObject.ExpandedName) + [pscustomobject]@{ + Depth = ($InputObject.Path.Count + 1) + ItemType = $InputObject.ItemType + Name = $Name + Path = $Path + Result = $InputObject.Result + FailedCount = $InputObject.FailedCount + FailedBlocksCount = $InputObject.FailedBlocksCount + FailedContainersCount = $InputObject.FailedContainersCount + PassedCount = $InputObject.PassedCount + SkippedCount = $InputObject.SkippedCount + InconclusiveCount = $InputObject.InconclusiveCount + NotRunCount = $InputObject.NotRunCount + TotalCount = $InputObject.TotalCount + Duration = $InputObject.Duration + Executed = $InputObject.Executed + ExecutedAt = $InputObject.ExecutedAt + Version = $InputObject.Version + PSVersion = $InputObject.PSVersion + Plugins = $InputObject.Plugins + PluginConfiguration = $InputObject.PluginConfiguration + PluginData = $InputObject.PluginData + DiscoveryDuration = $InputObject.DiscoveryDuration + UserDuration = $InputObject.UserDuration + FrameworkDuration = $InputObject.FrameworkDuration + } } default { Write-Error "Unknown object type: [$($InputObject.GetType().Name)]" diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 50aaf31d..17cdaa61 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -103,7 +103,7 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting test results to [$jsonOutputPath]" - $testResults | ConvertTo-Json -Depth 2 | Out-File -FilePath $jsonOutputPath + $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { From c077b0191b02ae7b15cef6187a5c37e924cb2812 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 18:37:00 +0100 Subject: [PATCH 19/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Get-Pe?= =?UTF-8?q?sterTestTree=20to=20return=20duration=20properties=20as=20ticks?= =?UTF-8?q?=20for=20improved=20precision=20in=20test=20result=20metrics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Helpers.psm1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index b073603a..809e10b1 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -712,7 +712,7 @@ filter Get-PesterTestTree { InconclusiveCount = $InputObject.InconclusiveCount NotRunCount = $InputObject.NotRunCount TotalCount = $InputObject.TotalCount - Duration = $InputObject.Duration + Duration = $InputObject.Duration.Ticks Executed = $InputObject.Executed ExecutedAt = $InputObject.ExecutedAt Version = $InputObject.Version @@ -720,9 +720,9 @@ filter Get-PesterTestTree { Plugins = $InputObject.Plugins PluginConfiguration = $InputObject.PluginConfiguration PluginData = $InputObject.PluginData - DiscoveryDuration = $InputObject.DiscoveryDuration - UserDuration = $InputObject.UserDuration - FrameworkDuration = $InputObject.FrameworkDuration + DiscoveryDuration = $InputObject.DiscoveryDuration.Ticks + UserDuration = $InputObject.UserDuration.Ticks + FrameworkDuration = $InputObject.FrameworkDuration.Ticks } } 'Block' { @@ -744,7 +744,7 @@ filter Get-PesterTestTree { InconclusiveCount = $InputObject.InconclusiveCount NotRunCount = $InputObject.NotRunCount TotalCount = $InputObject.TotalCount - Duration = $InputObject.Duration + Duration = $InputObject.Duration.Ticks Executed = $InputObject.Executed ExecutedAt = $InputObject.ExecutedAt Version = $InputObject.Version @@ -752,9 +752,9 @@ filter Get-PesterTestTree { Plugins = $InputObject.Plugins PluginConfiguration = $InputObject.PluginConfiguration PluginData = $InputObject.PluginData - DiscoveryDuration = $InputObject.DiscoveryDuration - UserDuration = $InputObject.UserDuration - FrameworkDuration = $InputObject.FrameworkDuration + DiscoveryDuration = $InputObject.DiscoveryDuration.Ticks + UserDuration = $InputObject.UserDuration.Ticks + FrameworkDuration = $InputObject.FrameworkDuration.Ticks } } 'Test' { @@ -773,7 +773,7 @@ filter Get-PesterTestTree { InconclusiveCount = $InputObject.InconclusiveCount NotRunCount = $InputObject.NotRunCount TotalCount = $InputObject.TotalCount - Duration = $InputObject.Duration + Duration = $InputObject.Duration.Ticks Executed = $InputObject.Executed ExecutedAt = $InputObject.ExecutedAt Version = $InputObject.Version @@ -781,9 +781,9 @@ filter Get-PesterTestTree { Plugins = $InputObject.Plugins PluginConfiguration = $InputObject.PluginConfiguration PluginData = $InputObject.PluginData - DiscoveryDuration = $InputObject.DiscoveryDuration - UserDuration = $InputObject.UserDuration - FrameworkDuration = $InputObject.FrameworkDuration + DiscoveryDuration = $InputObject.DiscoveryDuration.Ticks + UserDuration = $InputObject.UserDuration.Ticks + FrameworkDuration = $InputObject.FrameworkDuration.Ticks } } default { From 85f43d941627a194429755048e3ecd98c200dab1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 18:48:18 +0100 Subject: [PATCH 20/33] Enhance JSON export of code coverage results by adding compression for reduced file size --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 17cdaa61..4235971a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -109,7 +109,7 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting code coverage results to [$jsonOutputPath]" - $testResults.CodeCoverage | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath + $testResults.CodeCoverage | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath } } From 1ca395d54ced5a05ae0cb488b4c0da17a70de15d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 18:59:59 +0100 Subject: [PATCH 21/33] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20JSON?= =?UTF-8?q?=20export=20depth=20for=20code=20coverage=20results=20to=20impr?= =?UTF-8?q?ove=20performance=20and=20reduce=20output=20size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 4235971a..b7b1901d 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -109,7 +109,7 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting code coverage results to [$jsonOutputPath]" - $testResults.CodeCoverage | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath + $testResults.CodeCoverage | ConvertTo-Json -Depth 1 -Compress | Out-File -FilePath $jsonOutputPath } } From 926172db2820e28a985601719aeea3845f638cf1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 19:09:58 +0100 Subject: [PATCH 22/33] Adjust JSON export depth for test results to enhance performance and maintain consistency in code coverage output --- scripts/main.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b7b1901d..28fb47d9 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -103,13 +103,13 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting test results to [$jsonOutputPath]" - $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath + $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 1 | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting code coverage results to [$jsonOutputPath]" - $testResults.CodeCoverage | ConvertTo-Json -Depth 1 -Compress | Out-File -FilePath $jsonOutputPath + $testResults.CodeCoverage | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath } } From 05d58bb9b191cdfe25a8fcbc621cb7223e0e1846 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 19:18:16 +0100 Subject: [PATCH 23/33] Enhance Get-PesterTestTree to return duration properties as ticks for improved precision in test result metrics and update JSON export depth for better output handling --- scripts/Helpers.psm1 | 32 ++++++++++++++++---------------- scripts/main.ps1 | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 809e10b1..50f415ef 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -679,7 +679,6 @@ filter Get-PesterTestTree { InconclusiveCount = $InputObject.InconclusiveCount NotRunCount = $InputObject.NotRunCount TotalCount = $InputObject.TotalCount - Duration = $InputObject.Duration Executed = $InputObject.Executed ExecutedAt = $InputObject.ExecutedAt Version = $InputObject.Version @@ -688,9 +687,10 @@ filter Get-PesterTestTree { PluginConfiguration = $InputObject.PluginConfiguration PluginData = $InputObject.PluginData Configuration = $configuration - DiscoveryDuration = $InputObject.DiscoveryDuration - UserDuration = $InputObject.UserDuration - FrameworkDuration = $InputObject.FrameworkDuration + Duration = [int64]$InputObject.Duration.Ticks + DiscoveryDuration = [int64]$InputObject.DiscoveryDuration.Ticks + UserDuration = [int64]$InputObject.UserDuration.Ticks + FrameworkDuration = [int64]$InputObject.FrameworkDuration.Ticks } } 'Container' { @@ -712,7 +712,6 @@ filter Get-PesterTestTree { InconclusiveCount = $InputObject.InconclusiveCount NotRunCount = $InputObject.NotRunCount TotalCount = $InputObject.TotalCount - Duration = $InputObject.Duration.Ticks Executed = $InputObject.Executed ExecutedAt = $InputObject.ExecutedAt Version = $InputObject.Version @@ -720,9 +719,10 @@ filter Get-PesterTestTree { Plugins = $InputObject.Plugins PluginConfiguration = $InputObject.PluginConfiguration PluginData = $InputObject.PluginData - DiscoveryDuration = $InputObject.DiscoveryDuration.Ticks - UserDuration = $InputObject.UserDuration.Ticks - FrameworkDuration = $InputObject.FrameworkDuration.Ticks + Duration = [int64]$InputObject.Duration.Ticks + DiscoveryDuration = [int64]$InputObject.DiscoveryDuration.Ticks + UserDuration = [int64]$InputObject.UserDuration.Ticks + FrameworkDuration = [int64]$InputObject.FrameworkDuration.Ticks } } 'Block' { @@ -744,7 +744,6 @@ filter Get-PesterTestTree { InconclusiveCount = $InputObject.InconclusiveCount NotRunCount = $InputObject.NotRunCount TotalCount = $InputObject.TotalCount - Duration = $InputObject.Duration.Ticks Executed = $InputObject.Executed ExecutedAt = $InputObject.ExecutedAt Version = $InputObject.Version @@ -752,9 +751,10 @@ filter Get-PesterTestTree { Plugins = $InputObject.Plugins PluginConfiguration = $InputObject.PluginConfiguration PluginData = $InputObject.PluginData - DiscoveryDuration = $InputObject.DiscoveryDuration.Ticks - UserDuration = $InputObject.UserDuration.Ticks - FrameworkDuration = $InputObject.FrameworkDuration.Ticks + Duration = [int64]$InputObject.Duration.Ticks + DiscoveryDuration = [int64]$InputObject.DiscoveryDuration.Ticks + UserDuration = [int64]$InputObject.UserDuration.Ticks + FrameworkDuration = [int64]$InputObject.FrameworkDuration.Ticks } } 'Test' { @@ -773,7 +773,6 @@ filter Get-PesterTestTree { InconclusiveCount = $InputObject.InconclusiveCount NotRunCount = $InputObject.NotRunCount TotalCount = $InputObject.TotalCount - Duration = $InputObject.Duration.Ticks Executed = $InputObject.Executed ExecutedAt = $InputObject.ExecutedAt Version = $InputObject.Version @@ -781,9 +780,10 @@ filter Get-PesterTestTree { Plugins = $InputObject.Plugins PluginConfiguration = $InputObject.PluginConfiguration PluginData = $InputObject.PluginData - DiscoveryDuration = $InputObject.DiscoveryDuration.Ticks - UserDuration = $InputObject.UserDuration.Ticks - FrameworkDuration = $InputObject.FrameworkDuration.Ticks + Duration = [int64]$InputObject.Duration.Ticks + DiscoveryDuration = [int64]$InputObject.DiscoveryDuration.Ticks + UserDuration = [int64]$InputObject.UserDuration.Ticks + FrameworkDuration = [int64]$InputObject.FrameworkDuration.Ticks } } default { diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 28fb47d9..4235971a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -103,7 +103,7 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting test results to [$jsonOutputPath]" - $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 1 | Out-File -FilePath $jsonOutputPath + $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { From 25f381ff34a8640a3db43c20e375fb8f3459d40e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 19:30:56 +0100 Subject: [PATCH 24/33] Adjust JSON export depth for test results to improve performance and reduce output size --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 4235971a..4ae34941 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -103,7 +103,7 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting test results to [$jsonOutputPath]" - $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath + $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 2 | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { From b1b3250db13ec5ce65753b32b3cab413cb0a4b2e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 19:39:39 +0100 Subject: [PATCH 25/33] Enhance JSON export for test results by increasing depth and adding compression to improve performance and reduce output size --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 4ae34941..51d32736 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -103,7 +103,7 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting test results to [$jsonOutputPath]" - $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 2 | Out-File -FilePath $jsonOutputPath + $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { From 8132b09621f7033c517fef7e823dc53f93e5569c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 19:44:03 +0100 Subject: [PATCH 26/33] Remove compression from JSON export for test results and code coverage to simplify output handling --- scripts/main.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 51d32736..17cdaa61 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -103,13 +103,13 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting test results to [$jsonOutputPath]" - $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath + $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting code coverage results to [$jsonOutputPath]" - $testResults.CodeCoverage | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath + $testResults.CodeCoverage | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath } } From e03ec14fe0786ea0d3cccd113a021ce19c21af41 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 20:06:36 +0100 Subject: [PATCH 27/33] Convert container configurations to hashtables in Get-PesterTestTree for improved data handling --- scripts/Helpers.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 50f415ef..0c77abc3 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -664,6 +664,9 @@ filter Get-PesterTestTree { $childPath = @($Path, $Name) $children.Add(($InputObject.Containers | Get-PesterTestTree -Path $childPath)) $configuration = $InputObject.Configuration | ConvertFrom-PesterConfiguration + $configuration.Containers = $InputObject.Configuration.Containers | ForEach-Object { + $_ | ConvertTo-Hashtable + } [pscustomobject]@{ Depth = 0 ItemType = 'TestSuite' From 7026911786063015dcb35d40ee63640245c141f4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 20:23:58 +0100 Subject: [PATCH 28/33] Enhance ConvertFrom-PesterConfiguration to handle container settings as custom objects for improved data structure and maintain verbose logging --- scripts/Helpers.psm1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 0c77abc3..e5f2e688 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -525,8 +525,17 @@ filter ConvertFrom-PesterConfiguration { $settingName = $setting.Name $settingValue = $setting.Value $settingValue = $OnlyModified ? $settingValue.Value : ($settingValue.IsModified ? $settingValue.Value : $settingValue.Default) - $subHash[$settingName] = $settingValue - Write-Verbose "[$categoryName] [$settingName] = $settingValue" -Verbose + if ($categoryName -eq 'Run' -and $settingName -eq 'Container') { + $settingValue | ForEach-Object { + $subHash[$settingName] = [pscustomobject]@{ + Path = $_.Path.ToString() + Data = $_.Data + } + } + } else { + $subHash[$settingName] = $settingValue + Write-Verbose "[$categoryName] [$settingName] = $settingValue" -Verbose + } } # Add the category sub-hashtable to the result even if empty, to preserve structure. @@ -664,9 +673,6 @@ filter Get-PesterTestTree { $childPath = @($Path, $Name) $children.Add(($InputObject.Containers | Get-PesterTestTree -Path $childPath)) $configuration = $InputObject.Configuration | ConvertFrom-PesterConfiguration - $configuration.Containers = $InputObject.Configuration.Containers | ForEach-Object { - $_ | ConvertTo-Hashtable - } [pscustomobject]@{ Depth = 0 ItemType = 'TestSuite' From 4666be3030a74e21056086c30026ddca825eb819 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 20:32:42 +0100 Subject: [PATCH 29/33] Enhance ConvertFrom-PesterConfiguration to improve verbose logging and handle container settings as custom objects for better data structure --- scripts/Helpers.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index e5f2e688..20d7a0c6 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -525,16 +525,16 @@ filter ConvertFrom-PesterConfiguration { $settingName = $setting.Name $settingValue = $setting.Value $settingValue = $OnlyModified ? $settingValue.Value : ($settingValue.IsModified ? $settingValue.Value : $settingValue.Default) + Write-Verbose "[$categoryName] [$settingName] = $settingValue" -Verbose if ($categoryName -eq 'Run' -and $settingName -eq 'Container') { - $settingValue | ForEach-Object { - $subHash[$settingName] = [pscustomobject]@{ + $subHash[$settingName] = $settingValue | ForEach-Object { + [pscustomobject]@{ Path = $_.Path.ToString() Data = $_.Data } } } else { $subHash[$settingName] = $settingValue - Write-Verbose "[$categoryName] [$settingName] = $settingValue" -Verbose } } From 5183b58a83df50e95946d0975f0f1c477b7ae198 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 20:40:10 +0100 Subject: [PATCH 30/33] Refactor ConvertFrom-PesterConfiguration to use a list for container settings, improving data handling and structure --- scripts/Helpers.psm1 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 20d7a0c6..1bbc83e8 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -527,12 +527,16 @@ filter ConvertFrom-PesterConfiguration { $settingValue = $OnlyModified ? $settingValue.Value : ($settingValue.IsModified ? $settingValue.Value : $settingValue.Default) Write-Verbose "[$categoryName] [$settingName] = $settingValue" -Verbose if ($categoryName -eq 'Run' -and $settingName -eq 'Container') { - $subHash[$settingName] = $settingValue | ForEach-Object { - [pscustomobject]@{ - Path = $_.Path.ToString() - Data = $_.Data - } + $containers = [System.Collections.Generic.List[object]]::new() + foreach ($container in $settingValue) { + $containers.Add( + [pscustomobject]@{ + Path = $container.Path.ToString() + Data = $container.Data + } + ) } + $subHash[$settingName] = $containers } else { $subHash[$settingName] = $settingValue } From e7270520d9adaa70e5b2856a1535f4644aff464e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 20:42:58 +0100 Subject: [PATCH 31/33] Enhance ConvertFrom-PesterConfiguration to include detailed verbose logging for container settings --- scripts/Helpers.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index 1bbc83e8..e9d972b1 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -527,6 +527,7 @@ filter ConvertFrom-PesterConfiguration { $settingValue = $OnlyModified ? $settingValue.Value : ($settingValue.IsModified ? $settingValue.Value : $settingValue.Default) Write-Verbose "[$categoryName] [$settingName] = $settingValue" -Verbose if ($categoryName -eq 'Run' -and $settingName -eq 'Container') { + Write-Verbose ($settingValue | ConvertTo-Json -Depth 1 | Out-String) -Verbose $containers = [System.Collections.Generic.List[object]]::new() foreach ($container in $settingValue) { $containers.Add( From 85720e2378be7d0ddb9da1c99b2b03fb12b45481 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 21:00:40 +0100 Subject: [PATCH 32/33] Update ConvertFrom-PesterConfiguration to use FullName for container paths in verbose logging --- scripts/Helpers.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Helpers.psm1 b/scripts/Helpers.psm1 index e9d972b1..27869606 100644 --- a/scripts/Helpers.psm1 +++ b/scripts/Helpers.psm1 @@ -532,7 +532,7 @@ filter ConvertFrom-PesterConfiguration { foreach ($container in $settingValue) { $containers.Add( [pscustomobject]@{ - Path = $container.Path.ToString() + Path = $container.Item.FullName Data = $container.Data } ) From fd3cbf2f6c197e953efab09325a50519aa54bf54 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 21:14:42 +0100 Subject: [PATCH 33/33] Optimize JSON output generation by adding compression for test results and code coverage exports --- scripts/main.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 17cdaa61..51d32736 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -103,13 +103,13 @@ LogGroup 'Eval - Set outputs' { if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting test results to [$jsonOutputPath]" - $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath + $testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath } if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) { $jsonOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value -Replace '\.xml$', '.json' Write-Output "Exporting code coverage results to [$jsonOutputPath]" - $testResults.CodeCoverage | ConvertTo-Json -Depth 100 | Out-File -FilePath $jsonOutputPath + $testResults.CodeCoverage | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath } }