pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.11k stars 473 forks source link

Report code coverage that includes P tests #2478

Closed nohwnd closed 5 months ago

nohwnd commented 6 months ago

Testing how we could measure CodeCoverage of Pester and P tests. The code above runs, except for one test in mock, which is strange since we can Profile pester tests. Maybe it was some fluke.

image

Fix #2475

nohwnd commented 6 months ago

The error detection is sweet. Took me half evening yesterday to figure out where the code was stopping to properly trace, and this does it automatically:

image

nohwnd commented 6 months ago

test.ps1 -cc

image

nohwnd commented 6 months ago

With inline.

image

Not sure what is the difference, but it is small enough to ignore.

nohwnd commented 6 months ago

shows summary in UI now as well, it is not super helpful, but it is there.

image

johlju commented 6 months ago

Fyi. The task PublishCodeCoverageResults@2 does not (yet?) support line coverage, but if using v1 the Pester.psm1 will be clickable and show coverage per line.

nohwnd commented 6 months ago

I tried that and I still don't see the uncovered lines in the breakdown. image

@fhnaseer is there a way to make the new code coverage view (two posts above) more detailed than just summary per file? we are producing jacoco output.

johlju commented 6 months ago

See example here where you can see it show hits and misses per line (if you click on a file): https://dev.azure.com/dsccommunity/SqlServerDsc/_build/results?buildId=8834&view=codecoverage-tab

It only works with v1 though as I mentioned. See you updated it to v1 so maybe it doesn't find the sources, a parameter of the task that should point to the files that was tested. 🤔

In the SqlServerDsc case we use ModuleBuilder to build the module. So there are some extra work in our pipeline to convert the line numbers in JaCoCo back to the source files and their line numbers even if we tested the built module (psm1). That is why all commands etc is in separate files. That should not be needed in this case though.