Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Relative paths for reports are relative to current folder after all tests completed, not to the original pester folder.

Open nohwnd opened this issue 7 months ago • 2 comments

Checklist

What is the issue?

Tests can set current path, and we generate reports before we return to the original PWD. So the test results can be placed into a "random" folder depending on which tests user executed.

Invoke-Pester -Container (New-PesterContainer -ScriptBlock { 
    Describe "a" {
        It "b" { 
            $testDrive = (Get-PSDrive TestDrive).Root
            $f = New-Item -ItemType Directory -Path "$testDrive/will-delete" -Force
            Set-Location $f
        }
    }
}) -CI

Will fail with,

Result 1 - Error 1:Resolve-Path: Cannot find path 'C:\Users\jajares\AppData\Local\Temp\f9da4b3f-18d6-4e1d-9755-db812fe31754\will-delete' because it does not exist.

at GetFullPath, C:\Users\jajares\Documents\PowerShell\Modules\Pester\5.7.1\Pester.psm1: line 17987
at Export-XmlReport, C:\Users\jajares\Documents\PowerShell\Modules\Pester\5.7.1\Pester.psm1: line 18141
at Export-PesterResult, C:\Users\jajares\Documents\PowerShell\Modules\Pester\5.7.1\Pester.psm1: line 18012
at <ScriptBlock>, C:\Users\jajares\Documents\PowerShell\Modules\Pester\5.7.1\Pester.psm1: line 18501
at Invoke-PluginStep, C:\Users\jajares\Documents\PowerShell\Modules\Pester\5.7.1\Pester.psm1: line 1800
at Invoke-Pester<End>, C:\Users\jajares\Documents\PowerShell\Modules\Pester\5.7.1\Pester.psm1: line 4991
at <ScriptBlock>, untitled:Untitled-2: line 1
at <ScriptBlock>, <No file>: line 1

Because I stepped into test drive directory, which was then cleaned up by test drive, but the report code is trying to get current path relative to the current directory.

Expected Behavior

We would reset the path to original pwd before we start writing reports, so we resolve relative to the path from which invoke-pester was invoked.

Steps To Reproduce

No response

Describe your environment

No response

Possible Solution?

No response

nohwnd avatar Apr 17 '25 10:04 nohwnd

I am actually using 5.7.1 pester, will double check if latest fixed this.

nohwnd avatar Apr 17 '25 10:04 nohwnd

Good catch. Should still be broken in latest. We should just resolve the outputpaths early in Resolve-TestResultConfiguration and Resolve-CoverageConfiguration

fflaten avatar Apr 17 '25 10:04 fflaten