Skip to content

Commit df22ec4

Browse files
committed
fix(#260): enhance output handling in integration tests
- replace output joining with Get-NovaPublicCommandIntegrationOutputText for better formatting - normalize whitespace in output assertions for consistency
1 parent d83d825 commit df22ec4

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

tests/TestHelpers/PublicCommandIntegration.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ function Invoke-NovaPublicCommandIntegrationInProjectRoot {
4747
return Invoke-NovaPublicCommandIntegrationInLocation -Path $ProjectRoot -ScriptBlock $ScriptBlock
4848
}
4949

50+
function Get-NovaPublicCommandIntegrationOutputText {
51+
[CmdletBinding()]
52+
param(
53+
[Parameter(Mandatory)][object[]]$Output,
54+
[switch]$NormalizeWhitespace
55+
)
56+
57+
$text = @($Output) -join [Environment]::NewLine
58+
$text = [regex]::Replace($text, '\x1B\[[0-?]*[ -/]*[@-~]', '')
59+
if ($NormalizeWhitespace) {
60+
$text = [regex]::Replace($text, '\s+', ' ')
61+
}
62+
63+
return $text.Trim()
64+
}
65+
5066
function Invoke-NovaPublicCommandIntegrationInIsolatedSession {
5167
[CmdletBinding()]
5268
param(

tests/public/InvokeNovaTest.Integration.Tests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Describe 'Invoke-NovaTest integration' {
1010
Invoke-NovaTest -WhatIf
1111
}
1212

13-
$result.ExitCode | Should -Be 0 -Because ($result.Output -join [Environment]::NewLine)
13+
$result.ExitCode | Should -Be 0 -Because (Get-NovaPublicCommandIntegrationOutputText -Output $result.Output)
1414
}
1515

1616
It 'fails early when the isolated session cannot resolve a supported Pester 5.x module' {
@@ -27,7 +27,7 @@ Describe 'Invoke-NovaTest integration' {
2727
}
2828
}
2929

30-
$outputText = $result.Output -join [Environment]::NewLine
30+
$outputText = Get-NovaPublicCommandIntegrationOutputText -Output $result.Output -NormalizeWhitespace
3131
$result.ExitCode | Should -Not -Be 0
3232
$outputText | Should -Match 'Pester'
3333
$outputText | Should -Match 'Import-Module'
@@ -44,7 +44,7 @@ Describe 'Invoke-NovaTest integration' {
4444
}
4545
}
4646

47-
$result.ExitCode | Should -Be 0 -Because ($result.Output -join [Environment]::NewLine)
47+
$result.ExitCode | Should -Be 0 -Because (Get-NovaPublicCommandIntegrationOutputText -Output $result.Output)
4848
}
4949

5050
It 'rejects non-file Run.Container overrides from the built module' {
@@ -62,7 +62,7 @@ Describe 'Invoke-NovaTest integration' {
6262
}
6363

6464
$result.ExitCode | Should -Not -Be 0
65-
($result.Output -join [Environment]::NewLine) | Should -Match 'ScriptBlock and other container types are not supported'
65+
(Get-NovaPublicCommandIntegrationOutputText -Output $result.Output -NormalizeWhitespace) | Should -Match 'ScriptBlock and other container types are not supported'
6666
}
6767

6868
It 'rejects unsupported override shapes from the built module' {
@@ -75,6 +75,6 @@ Describe 'Invoke-NovaTest integration' {
7575
}
7676

7777
$result.ExitCode | Should -Not -Be 0
78-
($result.Output -join [Environment]::NewLine) | Should -Match 'Unsupported override path: Run.Path'
78+
(Get-NovaPublicCommandIntegrationOutputText -Output $result.Output -NormalizeWhitespace) | Should -Match 'Unsupported override path: Run.Path'
7979
}
8080
}

tests/public/TestNovaBuild.Integration.Tests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Describe 'Test-NovaBuild integration' {
1010
Test-NovaBuild -WhatIf
1111
}
1212

13-
$result.ExitCode | Should -Be 0 -Because ($result.Output -join [Environment]::NewLine)
13+
$result.ExitCode | Should -Be 0 -Because (Get-NovaPublicCommandIntegrationOutputText -Output $result.Output)
1414
}
1515

1616
It 'fails early when the isolated session cannot resolve a supported Pester 5.x module' {
@@ -27,7 +27,7 @@ Describe 'Test-NovaBuild integration' {
2727
}
2828
}
2929

30-
$outputText = $result.Output -join [Environment]::NewLine
30+
$outputText = Get-NovaPublicCommandIntegrationOutputText -Output $result.Output -NormalizeWhitespace
3131
$result.ExitCode | Should -Not -Be 0
3232
$outputText | Should -Match 'Pester'
3333
$outputText | Should -Match 'Import-Module'
@@ -45,8 +45,8 @@ Describe 'Test-NovaBuild integration' {
4545
Test-NovaBuild 3>&1
4646
}
4747

48-
$result.ExitCode | Should -Be 0 -Because ($result.Output -join [Environment]::NewLine)
49-
($result.Output -join [Environment]::NewLine) | Should -Match "No build-validation integration tests matching '\*\.Integration\.Tests\.ps1' were discovered for NovaExampleModule\."
48+
$result.ExitCode | Should -Be 0 -Because (Get-NovaPublicCommandIntegrationOutputText -Output $result.Output)
49+
(Get-NovaPublicCommandIntegrationOutputText -Output $result.Output -NormalizeWhitespace) | Should -Match "No build-validation integration tests matching '\*\.Integration\.Tests\.ps1' were discovered for NovaExampleModule\."
5050
}
5151

5252
It 'passes for a scaffolded example whose project name differs from the packaged template name' {
@@ -64,6 +64,6 @@ Describe 'Test-NovaBuild integration' {
6464
Test-NovaBuild
6565
}
6666

67-
$result.ExitCode | Should -Be 0 -Because ($result.Output -join [Environment]::NewLine)
67+
$result.ExitCode | Should -Be 0 -Because (Get-NovaPublicCommandIntegrationOutputText -Output $result.Output)
6868
}
6969
}

0 commit comments

Comments
 (0)