How to make the output in the pipeline appear on the console when running pester tests?
Asked Answered
S

1

2

By default, the output in the pipeline is hidden,But sometimes I really want to know the output at that time.

Of course, I knew I could add additional commands, such as write-host or out-default.

But does Pester itself have a mechanism to make the output display properly?

I checked the help document and didn't find the relevant content, so I came here for help.

Sodomite answered 29/12, 2020 at 10:11 Comment(0)
F
2

It is possible to write a custom Should wrapper (proxy) using this technique. The wrapper can write the pipeline objects to the console.

Here is a complete example of such a Should wrapper and how to override Pester's Should.

To apply it to your case, edit the process{} block of the wrapper like this:

process {
    try {
        # Here $_ is the current pipeline object
        Write-Host "Current test case input:`n$( $_ | Out-String )"
        
        # forward it to "process" block of original "Should"
        $steppablePipeline.Process( $_ )
    } catch {
        throw
    }
}
Foothold answered 8/1, 2021 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.