Pester icon indicating copy to clipboard operation
Pester copied to clipboard

ShowStartMarkers is missing data driven replacements

Open davidmatson opened this issue 8 months ago • 1 comments

Checklist

What is the issue?

I wanted to add a new PTest for this case, but I can't find the right implementation to make the test pass.

        t 'Test names are evaluated after data driven replacements when when ShowStartMarkers is enabled' {
            $sb = {
                $PesterPreference = [PesterConfiguration]::Default
                $PesterPreference.Output.Verbosity = 'Detailed'
                $PesterPreference.Debug.ShowStartMarkers = $true
                $PesterPreference.Output.CIFormat = 'None'
                $PesterPreference.Output.RenderMode = 'ConsoleColor'

                $container = New-PesterContainer -ScriptBlock {
                    Describe 'd1' {
                        It 'Iteration <_>' -ForEach (@(1..3)) {
                            1 | Should -Be 1
                        }
                    }
                }
                Invoke-Pester -Container $container
            }

            $output = Invoke-InNewProcess $sb
            # only print the relevant part of output
            $null, $run = $output -join "`n" -split 'Running tests.'
            $run | Write-Host

            $i1Start = $output | Select-String -Pattern '\[\|\] Iteration 1\.\.\.$'
            @($i1Start).Count | Verify-Equal 1
            $i1Start = $output | Select-String -Pattern '\[\|\] Iteration 2\.\.\.$'
            @($i2Start).Count | Verify-Equal 1
            $i1Start = $output | Select-String -Pattern '\[\|\] Iteration 3\.\.\.$'
            @($i3Start).Count | Verify-Equal 1
        }

I think that currently there is no Plugin step after the expansion is done, and fixing this bug would require creating a new Plugin step, or something like that, but I may be mistaken. @nohwnd @fflaten - thoughts?

Expected Behavior

Test name includes expansions

Steps To Reproduce

see snippet above

Describe your environment

No response

Possible Solution?

No response

davidmatson avatar Apr 08 '25 19:04 davidmatson

I believe EachTestSetupStart is called here: https://github.com/pester/Pester/blob/c5646c8691f256ac0f9216a72359da6f4d4336c5/src/Pester.Runtime.ps1#L572

and then the expansions happen later in the same function: https://github.com/pester/Pester/blob/c5646c8691f256ac0f9216a72359da6f4d4336c5/src/Pester.Runtime.ps1#L650

I guess another possible solution would be to move the expansion above EachTestSetupStart. I'm not sure what the ramifications of that change would be though and whether it would be a good idea.

davidmatson avatar Apr 08 '25 19:04 davidmatson