Skip to content

Commit e11f22b

Browse files
nohwndCopilot
andcommitted
Fix #2515: Include hidden folders in test discovery on Linux
Copilot-generated fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d5f7c87 commit e11f22b

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/Pester.RSpec.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
foreach ($item in $items) {
3131
if ($item.PSIsContainer) {
3232
# this is an existing directory search it for tests file
33-
& $SafeCommands['Get-ChildItem'] -Recurse -Path $item -Filter "*$Extension" -File
33+
# use -Force to include hidden items (e.g. dot-prefixed folders on Linux)
34+
& $SafeCommands['Get-ChildItem'] -Recurse -Path $item -Filter "*$Extension" -File -Force
3435
}
3536
elseif ("FileSystem" -ne $item.PSProvider.Name) {
3637
# item is not a directory and exists but is not a file so we are not interested
@@ -60,7 +61,8 @@
6061
else {
6162
# this is a path that does not exist so let's hope it is
6263
# a wildcarded path that will resolve to some files
63-
& $SafeCommands['Get-ChildItem'] -Recurse -Path $p -Filter "*$Extension" -File
64+
# use -Force to include hidden items (e.g. dot-prefixed folders on Linux)
65+
& $SafeCommands['Get-ChildItem'] -Recurse -Path $p -Filter "*$Extension" -File -Force
6466
}
6567
}
6668

tst/Pester.RSpec.ts.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,4 +2966,43 @@ i -PassThru:$PassThru {
29662966
$ex.Exception.Message | Verify-Like '*Unbound scriptblock*'
29672967
}
29682968
}
2969+
2970+
# Regression test for https://github.com/pester/Pester/issues/2515
2971+
# Find-File should discover test files inside hidden (dot-prefixed) directories.
2972+
# Without -Force on Get-ChildItem, hidden folders are silently skipped.
2973+
b "Find-File discovers hidden folders" {
2974+
t "discovers test files in dot-prefixed (hidden) subdirectories" {
2975+
$tempDir = Join-Path ([IO.Path]::GetTempPath()) "PesterHidden_$([IO.Path]::GetRandomFileName().Substring(0,4))"
2976+
$hiddenDir = Join-Path $tempDir '.hidden'
2977+
$null = New-Item -ItemType Directory -Path $hiddenDir -Force
2978+
$testFile = Join-Path $hiddenDir 'MyHidden.Tests.ps1'
2979+
Set-Content -Path $testFile -Value "Describe 'Hidden' { It 'works' { `$true | Should -Be `$true } }"
2980+
2981+
try {
2982+
$found = & (Get-Module Pester) { Find-File -Path $args[0] -Extension '.Tests.ps1' } $tempDir
2983+
$found | Should -Not -BeNullOrEmpty
2984+
($found | ForEach-Object { $_.FullName }) | Should -Contain $testFile
2985+
}
2986+
finally {
2987+
Remove-Item -Path $tempDir -Recurse -Force
2988+
}
2989+
}
2990+
2991+
t "discovers test files in nested hidden directories" {
2992+
$tempDir = Join-Path ([IO.Path]::GetTempPath()) "PesterHidden2_$([IO.Path]::GetRandomFileName().Substring(0,4))"
2993+
$nestedHidden = Join-Path $tempDir '.config/tests'
2994+
$null = New-Item -ItemType Directory -Path $nestedHidden -Force
2995+
$testFile = Join-Path $nestedHidden 'Deep.Tests.ps1'
2996+
Set-Content -Path $testFile -Value "Describe 'Deep' { It 'works' { `$true | Should -Be `$true } }"
2997+
2998+
try {
2999+
$found = & (Get-Module Pester) { Find-File -Path $args[0] -Extension '.Tests.ps1' } $tempDir
3000+
$found | Should -Not -BeNullOrEmpty
3001+
($found | ForEach-Object { $_.FullName }) | Should -Contain $testFile
3002+
}
3003+
finally {
3004+
Remove-Item -Path $tempDir -Recurse -Force
3005+
}
3006+
}
3007+
}
29693008
}

0 commit comments

Comments
 (0)