Skip to content

Fix #2515: Include hidden folders in test discovery on Linux#2693

Merged
nohwnd merged 4 commits into
pester:mainfrom
nohwnd:fix-2515-hidden-folders
Jun 12, 2026
Merged

Fix #2515: Include hidden folders in test discovery on Linux#2693
nohwnd merged 4 commits into
pester:mainfrom
nohwnd:fix-2515-hidden-folders

Conversation

@nohwnd

@nohwnd nohwnd commented Apr 3, 2026

Copy link
Copy Markdown
Member

Fix #2515

Added -Force to Get-ChildItem calls in Find-File so hidden (dot-prefixed) folders like .github are included in test discovery on Linux.

Copilot-generated fix.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

@nohwnd

nohwnd commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

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.

@nohwnd nohwnd force-pushed the fix-2515-hidden-folders branch from 6b33792 to e11f22b Compare April 3, 2026 10:17
Comment thread tst/Pester.RSpec.ts.ps1 Outdated
Comment thread tst/Pester.RSpec.ts.ps1 Outdated
@nohwnd

nohwnd commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

I see no test for excluding .git folder, which has lot of files that we are almost 100% sure to not care about.

@nohwnd

nohwnd commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

🤖 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>
@nohwnd nohwnd force-pushed the fix-2515-hidden-folders branch from e11f22b to a47e8c6 Compare April 3, 2026 13:59
Comment thread src/Pester.RSpec.ps1 Outdated
$filteredFiles = foreach ($f in $files) {
# normalize backslashes for cross-platform ease of use
$normalizedPath = $f.FullName -replace "/", "\"
$dominated = $false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does dominated mean in this context?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Pester.RSpec.ps1 Outdated
# 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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

nohwnd and others added 2 commits June 11, 2026 18:41
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>
@nohwnd nohwnd force-pushed the fix-2515-hidden-folders branch from b12f1e9 to 0aba9c8 Compare June 11, 2026 16:55
@nohwnd nohwnd marked this pull request as ready for review June 11, 2026 17:09
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>
@nohwnd nohwnd merged commit d0be71a into pester:main Jun 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test discovery on linux fails to find tests in hidden folders

1 participant