Skip to content

Pester fails during code coverage setup if a hidden directory is included in CodeCoverage.Path #2327

Open
@martincostello

Description

@martincostello

Checklist

What is the issue?

I have a project where I'm using pester where I use a dot-prefixed folder to provide a sample in a directory to ensure it sorts first above a sequential list of numbers for other directory names, for example:

.sample
1
2
3
<etc>

If I explicitly add all folders into the CodeCoverage.Path setting of the Pester configuration like so, specifying -Force to ensure hidden folders are returned (because of the . prefix):

$config.CodeCoverage.Path = Get-ChildItem -Path (Join-Path $PSScriptRoot "migrations") -Directory -Force | ForEach-Object { $_.FullName }

Then Pester fails before tests start to run with an error similar to the below:

Pester v5.4.0

Starting discovery in 2 files.
Discovery found 14 tests in 234ms.
Starting code coverage.
Invoking step RunStart failed:
Result :Error :
Get-Item: Could not find item
/runner/_work/project-name/project-name/migrations/.sample.

at Get-CodeCoverageFilePaths, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line 85[9](https://github.je-labs.com/codeflow/repo-migrations/runs/1440788?check_suite_focus=true#step:5:10)1
at Resolve-CoverageInfo, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line 8566
at Get-CoverageInfoFromUserInput, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line 8497
at Enter-CoverageAnalysis, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line 8376
at <ScriptBlock>, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line 8317
at Invoke-PluginStep, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line 1773
at Run-Test, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line [15](https://github.je-labs.com/codeflow/repo-migrations/runs/1440788?check_suite_focus=true#step:5:16)73
at Invoke-Test, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line 2475
at Invoke-Pester<End>, /home/runner/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1: line 5272
at <ScriptBlock>, /runner/_work/repo-migrations/repo-migrations/test.ps1: line [19](https://github.je-labs.com/codeflow/repo-migrations/runs/1440788?check_suite_focus=true#step:5:20)

Expected Behavior

Pester successfully runs code coverage and the tests.

Steps To Reproduce

No response

Describe your environment

From WSL on Windows 11 running Ubuntu 22.04:

Pester version     : 5.4.0 /home/martin/.local/share/powershell/Modules/Pester/5.4.0/Pester.psm1
PowerShell version : 7.3.3
OS version         : Unix 5.15.90.1

This also occurs in a Linux container running Ubuntu in GitHub Actions, which is where I originally found the issue as I have a Windows development machine and the issue was not apparent there due to the different handling of folders with a . prefix.

Possible Solution?

From a cursory look at the code pointed to by the stack trace, it looks like -Force would needed to be passed through to this call to Get-Item so the directories/files are found?

$item = & $SafeCommands['Get-Item'] -LiteralPath $path

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions