Skip to content

Commit 5510607

Browse files
committed
🚜 [refactor] Add injectable output-redirected delegate and update tests/metadata
- 🚜 [refactor] ColorScripts-Enhanced.psm1: Make Test-ColorScriptTextEmission consult $script:IsOutputRedirectedDelegate when present, falling back to [Console]::IsOutputRedirected. This makes console-redirection detection injectable and deterministic for tests. - 🧪 [test] Update tests (TargetedCoverage, AdditionalCoverage, CoverageCompletion, CoverageFinalization) to use the delegate-aware expectation or compute expected redirection dynamically instead of assuming false. Also harden tests: verify paths with Test-Path before Resolve-Path, preserve/restore TMPDIR, parameterize and clean up TestDrive config roots, adjust cache-dir regex, and select/filter Get-ColorScriptEntry results for stable count assertions. - 📝 [docs] Bump module/help metadata to 2025.10.29.1847 (ModuleVersion and Help UICultureVersion) and update ReleaseNotes version in the manifest. - 🧹 [chore] Fix release-notes formatting: replace garbled header with "📦 Dependencies" in dist/LatestReleaseNotes.md and dist/PowerShellGalleryReleaseNotes.md. Signed-off-by: Nick2bad4u <20943337+Nick2bad4u@users.noreply.github.com>
1 parent 70aba6e commit 5510607

9 files changed

Lines changed: 85 additions & 19 deletions

ColorScripts-Enhanced/ColorScripts-Enhanced.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'ColorScripts-Enhanced.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2025.10.29.1629'
14+
ModuleVersion = '2025.10.29.1847'
1515

1616
# Supported PSEditions
1717
CompatiblePSEditions = @('Desktop', 'Core')
@@ -172,7 +172,7 @@ Full documentation: https://github.com/Nick2bad4u/ps-color-scripts-enhanced
172172

173173
# ReleaseNotes of this module
174174
ReleaseNotes = @'
175-
Version 2025.10.29.1629:
175+
Version 2025.10.29.1847:
176176
- Enhanced caching system with OS-wide cache in AppData
177177
- 6-19x performance improvement
178178
- Cache stored in centralized location

ColorScripts-Enhanced/ColorScripts-Enhanced.psm1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,12 @@ function Test-ColorScriptTextEmission {
854854

855855
$isRedirected = $false
856856
try {
857-
$isRedirected = [Console]::IsOutputRedirected
857+
if ($script:IsOutputRedirectedDelegate) {
858+
$isRedirected = & $script:IsOutputRedirectedDelegate
859+
}
860+
else {
861+
$isRedirected = [Console]::IsOutputRedirected
862+
}
858863
}
859864
catch {
860865
$isRedirected = $false

ColorScripts-Enhanced/en-US/ColorScripts-Enhanced_f77548d7-23eb-48ce-a6e0-f64b4758d995_HelpInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SupportedUICultures>
55
<UICulture>
66
<UICultureName>en-US</UICultureName>
7-
<UICultureVersion>2025.10.29.1629</UICultureVersion>
7+
<UICultureVersion>2025.10.29.1847</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>

Tests/ColorScripts-Enhanced.AdditionalCoverage.Tests.ps1

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,16 @@ namespace CoverageHost
19331933
Test-ColorScriptTextEmission -ReturnText $false -PassThru $true -PipelineLength 1 -BoundParameters @{}
19341934
}
19351935

1936-
$result | Should -BeFalse
1936+
$expected = InModuleScope ColorScripts-Enhanced {
1937+
if ($script:IsOutputRedirectedDelegate) {
1938+
& $script:IsOutputRedirectedDelegate
1939+
}
1940+
else {
1941+
[Console]::IsOutputRedirected
1942+
}
1943+
}
1944+
1945+
$result | Should -Be $expected
19371946
}
19381947

19391948
It "returns true for pipeline length greater than one" {
@@ -1960,7 +1969,16 @@ namespace CoverageHost
19601969
Test-ColorScriptTextEmission -ReturnText $false -PassThru $false -PipelineLength 1 -BoundParameters @{}
19611970
}
19621971

1963-
$result | Should -BeFalse
1972+
$expected = InModuleScope ColorScripts-Enhanced {
1973+
if ($script:IsOutputRedirectedDelegate) {
1974+
& $script:IsOutputRedirectedDelegate
1975+
}
1976+
else {
1977+
[Console]::IsOutputRedirected
1978+
}
1979+
}
1980+
1981+
$result | Should -Be $expected
19641982
}
19651983
}
19661984

Tests/ColorScripts-Enhanced.CoverageCompletion.Tests.ps1

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ Describe "ColorScripts-Enhanced coverage completion" {
9191
}
9292

9393
$result = Get-ColorScriptsConfigurationRoot
94-
$result | Should -Be ((Resolve-Path -LiteralPath $expected).ProviderPath)
94+
Test-Path -LiteralPath $expected | Should -BeTrue
95+
$resolvedExpected = (Resolve-Path -LiteralPath $expected).ProviderPath
96+
$result | Should -Be $resolvedExpected
9597
}
9698
finally {
9799
$script:ConfigurationRoot = $original.ConfigRoot
@@ -141,7 +143,9 @@ Describe "ColorScripts-Enhanced coverage completion" {
141143
}
142144

143145
$result = Get-ColorScriptsConfigurationRoot
144-
$result | Should -Be ((Resolve-Path -LiteralPath $expected).ProviderPath)
146+
Test-Path -LiteralPath $expected | Should -BeTrue
147+
$resolvedExpected = (Resolve-Path -LiteralPath $expected).ProviderPath
148+
$result | Should -Be $resolvedExpected
145149
}
146150
finally {
147151
$script:ConfigurationRoot = $original.ConfigRoot
@@ -503,10 +507,13 @@ Describe "ColorScripts-Enhanced coverage completion" {
503507
New-Item -ItemType Directory -Path $basePath -Force | Out-Null
504508
$originalTemp = $env:TEMP
505509
$originalTmp = $env:TMP
510+
$originalTmpDir = $env:TMPDIR
506511

507512
try {
508513
$env:TEMP = $basePath
509514
$env:TMP = $basePath
515+
$env:TMPDIR = $basePath
516+
$fallbackPath = [System.IO.Path]::Combine($basePath, 'ColorScripts-Enhanced')
510517

511518
$result = InModuleScope ColorScripts-Enhanced {
512519
$original = @{
@@ -576,6 +583,7 @@ Describe "ColorScripts-Enhanced coverage completion" {
576583
finally {
577584
if ($null -eq $originalTemp) { Remove-Item Env:TEMP -ErrorAction SilentlyContinue } else { $env:TEMP = $originalTemp }
578585
if ($null -eq $originalTmp) { Remove-Item Env:TMP -ErrorAction SilentlyContinue } else { $env:TMP = $originalTmp }
586+
if ($null -eq $originalTmpDir) { Remove-Item Env:TMPDIR -ErrorAction SilentlyContinue } else { $env:TMPDIR = $originalTmpDir }
579587
}
580588
}
581589

@@ -584,10 +592,12 @@ Describe "ColorScripts-Enhanced coverage completion" {
584592
New-Item -ItemType Directory -Path $basePath -Force | Out-Null
585593
$originalTemp = $env:TEMP
586594
$originalTmp = $env:TMP
595+
$originalTmpDir = $env:TMPDIR
587596

588597
try {
589598
$env:TEMP = $basePath
590599
$env:TMP = $basePath
600+
$env:TMPDIR = $basePath
591601

592602
$result = InModuleScope ColorScripts-Enhanced {
593603
$originalState = @{
@@ -619,11 +629,12 @@ Describe "ColorScripts-Enhanced coverage completion" {
619629
}
620630

621631
$result.Exists | Should -BeTrue
622-
$result.CacheDir | Should -Match 'ColorScripts-Enhanced([/\\]cache)?$'
632+
$result.CacheDir | Should -Match '(ColorScripts-Enhanced([/\\]cache)?|[/\\]cache)$'
623633
}
624634
finally {
625635
if ($null -eq $originalTemp) { Remove-Item Env:TEMP -ErrorAction SilentlyContinue } else { $env:TEMP = $originalTemp }
626636
if ($null -eq $originalTmp) { Remove-Item Env:TMP -ErrorAction SilentlyContinue } else { $env:TMP = $originalTmp }
637+
if ($null -eq $originalTmpDir) { Remove-Item Env:TMPDIR -ErrorAction SilentlyContinue } else { $env:TMPDIR = $originalTmpDir }
627638
}
628639
}
629640
}
@@ -699,8 +710,9 @@ Describe "ColorScripts-Enhanced coverage completion" {
699710
$store['auto-script'].Tags | Should -Contain 'AutoTag'
700711
$store['auto-script'].Tags | Should -Contain 'Category:AutoEnum'
701712

702-
$entry = Get-ColorScriptEntry -Name 'plain-script'
703-
$entry.Count | Should -Be 1
713+
$entries = Get-ColorScriptEntry
714+
$entry = @($entries | Where-Object { $_.Name -eq 'plain-script' })
715+
$entry | Should -HaveCount 1
704716
$entry[0].Category | Should -Be 'Abstract'
705717
$entry[0].Tags | Should -Contain 'Category:Abstract'
706718
$entry[0].Tags | Should -Contain 'AutoCategorized'
@@ -967,11 +979,15 @@ Describe "ColorScripts-Enhanced coverage completion" {
967979
$env:COLOR_SCRIPTS_ENHANCED_AUTOSHOW_ON_IMPORT = 'true'
968980
$env:CI = $null
969981
$env:GITHUB_ACTIONS = $null
982+
$configRoot = Join-Path -Path (Resolve-Path -LiteralPath 'TestDrive:\').ProviderPath -ChildPath ([guid]::NewGuid().ToString())
983+
New-Item -ItemType Directory -Path $configRoot -Force | Out-Null
970984

971985
try {
972-
$calls = InModuleScope ColorScripts-Enhanced {
986+
$calls = InModuleScope ColorScripts-Enhanced -Parameters @{ configRoot = $configRoot } {
987+
param($configRoot)
988+
[void]$configRoot
973989
Mock -CommandName Test-ConsoleOutputRedirected -ModuleName ColorScripts-Enhanced -MockWith { $false }
974-
Mock -CommandName Get-ColorScriptsConfigurationRoot -ModuleName ColorScripts-Enhanced -MockWith { 'C:\temp\config' }
990+
Mock -CommandName Get-ColorScriptsConfigurationRoot -ModuleName ColorScripts-Enhanced -MockWith { $configRoot }
975991
Mock -CommandName Get-ConfigurationDataInternal -ModuleName ColorScripts-Enhanced -MockWith {
976992
@{ Startup = @{ AutoShowOnImport = $false; DefaultScript = 'alpha' } }
977993
}
@@ -992,6 +1008,7 @@ Describe "ColorScripts-Enhanced coverage completion" {
9921008
if ($null -eq $originalOverride) { Remove-Item Env:COLOR_SCRIPTS_ENHANCED_AUTOSHOW_ON_IMPORT -ErrorAction SilentlyContinue } else { $env:COLOR_SCRIPTS_ENHANCED_AUTOSHOW_ON_IMPORT = $originalOverride }
9931009
if ($null -eq $originalCI) { Remove-Item Env:CI -ErrorAction SilentlyContinue } else { $env:CI = $originalCI }
9941010
if ($null -eq $originalGitHub) { Remove-Item Env:GITHUB_ACTIONS -ErrorAction SilentlyContinue } else { $env:GITHUB_ACTIONS = $originalGitHub }
1011+
if (Test-Path -LiteralPath $configRoot) { Remove-Item -LiteralPath $configRoot -Recurse -Force -ErrorAction SilentlyContinue }
9951012
}
9961013
}
9971014

Tests/ColorScripts-Enhanced.CoverageFinalization.Tests.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@
122122
}
123123

124124
$resolved = Get-ColorScriptsConfigurationRoot
125+
$exists = Test-Path -LiteralPath $expected
126+
$expectedPath = if ($exists) { (Resolve-Path -LiteralPath $expected).ProviderPath } else { $null }
125127
[pscustomobject]@{
126-
Expected = (Resolve-Path -LiteralPath $expected).ProviderPath
128+
Exists = $exists
129+
Expected = $expectedPath
127130
Result = $resolved
128131
}
129132
}
@@ -140,6 +143,7 @@
140143
}
141144
}
142145

146+
$result.Exists | Should -BeTrue
143147
$result.Result | Should -Be $result.Expected
144148
}
145149

@@ -177,8 +181,11 @@
177181
}
178182

179183
$resolved = Get-ColorScriptsConfigurationRoot
184+
$exists = Test-Path -LiteralPath $expected
185+
$expectedPath = if ($exists) { (Resolve-Path -LiteralPath $expected).ProviderPath } else { $null }
180186
[pscustomobject]@{
181-
Expected = (Resolve-Path -LiteralPath $expected).ProviderPath
187+
Exists = $exists
188+
Expected = $expectedPath
182189
Result = $resolved
183190
}
184191
}
@@ -194,6 +201,7 @@
194201
}
195202
}
196203

204+
$result.Exists | Should -BeTrue
197205
$result.Result | Should -Be $result.Expected
198206
}
199207
}

Tests/ColorScripts-Enhanced.TargetedCoverage.Tests.ps1

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,16 @@ Describe "ColorScripts-Enhanced targeted coverage" {
109109
Test-ColorScriptTextEmission -ReturnText $false -PassThru $true -PipelineLength 1 -BoundParameters @{}
110110
}
111111

112-
$result | Should -BeFalse
112+
$expected = InModuleScope ColorScripts-Enhanced {
113+
if ($script:IsOutputRedirectedDelegate) {
114+
& $script:IsOutputRedirectedDelegate
115+
}
116+
else {
117+
[Console]::IsOutputRedirected
118+
}
119+
}
120+
121+
$result | Should -Be $expected
113122
}
114123

115124
It "returns true for pipeline length greater than one" {
@@ -135,7 +144,16 @@ Describe "ColorScripts-Enhanced targeted coverage" {
135144
Test-ColorScriptTextEmission -ReturnText $false -PassThru $false -PipelineLength 1 -BoundParameters @{}
136145
}
137146

138-
$result | Should -BeFalse
147+
$expected = InModuleScope ColorScripts-Enhanced {
148+
if ($script:IsOutputRedirectedDelegate) {
149+
& $script:IsOutputRedirectedDelegate
150+
}
151+
else {
152+
[Console]::IsOutputRedirected
153+
}
154+
}
155+
156+
$result | Should -Be $expected
139157
}
140158
}
141159

dist/LatestReleaseNotes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ All notable changes to this project will be documented in this file.
1212
([compare](https://github.com/Nick2bad4u/PS-Color-Scripts-Enhanced/compare/9bb900c6b3370bcb0c519e4a77104d4ca87868c0...bfc9fc5bc8a96b077b9254e6bb11f6ce544f64e3))
1313

1414

15-
### 📦 Dependencies
15+
### 📦 Dependencies
1616

1717
- Merge pull request #6 from Nick2bad4u/dependabot/npm_and_yarn/npm-all-aaf6290c26
1818

dist/PowerShellGalleryReleaseNotes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
([compare](https://github.com/Nick2bad4u/PS-Color-Scripts-Enhanced/compare/9bb900c6b3370bcb0c519e4a77104d4ca87868c0...bfc9fc5bc8a96b077b9254e6bb11f6ce544f64e3))
77

88

9-
### 📦 Dependencies
9+
### 📦 Dependencies
1010

1111
- Merge pull request #6 from Nick2bad4u/dependabot/npm_and_yarn/npm-all-aaf6290c26
1212

0 commit comments

Comments
 (0)