Fix #2515: Include hidden folders in test discovery on Linux#2693
Conversation
|
read the comments on the original issue, you need to make sure you exclude .git folder, and also write tests, you have test-drive exactly for that. |
6b33792 to
e11f22b
Compare
|
I see no test for excluding .git folder, which has lot of files that we are almost 100% sure to not care about. |
|
🤖 Good point on .git exclusion. Will add test for that. Tests for hidden folder discovery were added in latest push. |
Add -Force to Get-ChildItem to discover dot-prefixed (hidden) folders on Linux. Exclude .git, .svn and .hg directories which are almost never wanted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e11f22b to
a47e8c6
Compare
| $filteredFiles = foreach ($f in $files) { | ||
| # normalize backslashes for cross-platform ease of use | ||
| $normalizedPath = $f.FullName -replace "/", "\" | ||
| $dominated = $false |
There was a problem hiding this comment.
what does dominated mean in this context?
There was a problem hiding this comment.
Gone in 0bd903b — the whole post-filter loop is gone, so there's no more dominated. The walker decides at each subdirectory whether to descend, so files under .git/.svn/.hg are never enumerated in the first place.
| # a wildcarded path that will resolve to some files | ||
| & $SafeCommands['Get-ChildItem'] -Recurse -Path $p -Filter "*$Extension" -File | ||
| # use -Force to include hidden items (e.g. dot-prefixed folders on Linux) | ||
| & $SafeCommands['Get-ChildItem'] -Recurse -Path $p -Filter "*$Extension" -File -Force |
There was a problem hiding this comment.
can you use exclude path to exclude .git? it is potentially expensive to enumerate, so we don't want to enumerate it and then filter it out.
There was a problem hiding this comment.
Done in 0bd903b. Rewrote the directory branch to walk the tree itself (new Find-FileInDirectory helper) so .git/.svn/.hg are skipped at the directory level — their contents are never enumerated.
The wildcard-fallback branch (when Test-Path returns false) still does a post-filter because the shape of those paths is harder to walk by hand, but that path is rare.
Added an equivalence test in tst/Pester.Tests.ps1 that asserts the result equals Get-ChildItem -Recurse -Filter '*.Tests.ps1' -File -Force minus VCS folders, and verified locally that removing the skip makes that test fail.
The previous tests just created dot-prefixed folders. On Windows that is not enough — the Hidden file attribute is what makes Get-ChildItem skip them without -Force. The dot-prefix-only tests therefore passed on both the buggy and fixed code on Windows, so they were not regression tests. Now the tests explicitly set the Hidden attribute on Windows (Linux/macOS treat the leading dot as hidden by convention, so no extra setup needed) and use the file-of-tests Verify-* helpers instead of Should so they match the rest of tst/Pester.RSpec.ts.ps1. Verified: all three new tests fail on origin/main src and pass on this branch: [n] discovers test files in dot-prefixed (hidden) subdirectories [n] discovers test files in nested hidden directories [n] excludes test files inside .git directories Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PS 5.1 does not define the $IsWindows automatic variable, and the hidden-folders tests run under Strict mode, so reading it directly threw 'The variable $IsWindows cannot be retrieved because it has not been set' in the PS_5_1_Windows_Server2022 leg. Reorder the check so the version comparison short-circuits before $IsWindows is touched: in PS 5.1 the first operand is $true and $IsWindows is never evaluated; in PS 6+ the variable is always set so reading it is safe. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b12f1e9 to
0aba9c8
Compare
Address the review feedback on this PR: - Walk the directory tree manually so .git/.svn/.hg are skipped at the directory level rather than enumerating their contents (which on a real repo can be hundreds of thousands of files for .git) and then filtering them back out at the end. The returned set is equivalent to Get-ChildItem -Recurse -Filter -File -Force minus the VCS subtrees. - Drop the post-filter loop and the unclear "dominated" variable; the fallback branch for unresolved wildcards still uses Get-ChildItem so it keeps a small inline check as a safety net for that less common path. - Move the hidden-folders tests from tst/Pester.RSpec.ts.ps1 into the existing Describe "Find-File" block in tst/Pester.Tests.ps1 so they can use TestDrive directly (and avoid Join-Path noise). - Add a stronger assertion that the result equals Get-ChildItem -Recurse -Force minus VCS folders, so regressions in either direction (hidden folders dropped, or VCS folders included) are caught. Verified locally by reverting the .git skip (the descend test and the equivalence test fail) and by filtering hidden items out of enumeration (both hidden-folder tests and the equivalence test fail). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fix #2515
Added
-ForcetoGet-ChildItemcalls inFind-Fileso hidden (dot-prefixed) folders like.githubare included in test discovery on Linux.Copilot-generated fix.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com