Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report code coverage that includes P tests #2478

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

nohwnd
Copy link
Member

@nohwnd nohwnd commented May 21, 2024

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.

  • The coverage shows 28% which seems too low, most of our tests run in process, so we maybe are resetting something somewhere. Or not pointing the code at the right files.

  • This also needs to be made compatible with inlining the module.

  • And Frode pointed out that tracer might not be both the same type.

  • we also need finally to tear down

  • and print summary

  • We are probably not setting that one extra BP that we should be seetting, if all breakpoints are removed Set-Trace will turn off, check profiler what it does, so we can re-enable the test in Mock that removes just it's breakpoints. Add detection of broken trace nohwnd/Profiler#67

  • Coverage tests fail but it is imho okay to skip these were mock tests, solved

  • coverage.ts tests break the coverage because they turn off tracing

  • this also higlights that when we profile Pester using PRofiler we are most likely not getting trace of all tests, so there are probably some other Perf wins hiding

image

Fix #2475

[Pester.Tracing.Tracer]::Register($tracer)
}
else {
$patched = $true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I just needed to check in patch and unpatch not just for profiler tracer, but also for pester tracer.

@fflaten this is what I meant by that. I should hide this under a Env variable probably, so we don't get into broken state after cancellation, as you pointed out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See few lines of the unchanged code above, it then makes more sense imho.

@nohwnd
Copy link
Member Author

nohwnd commented May 23, 2024

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
Copy link
Member Author

nohwnd commented May 23, 2024

test.ps1 -cc

image

@nohwnd
Copy link
Member Author

nohwnd commented May 23, 2024

With inline.

image

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

@nohwnd nohwnd marked this pull request as ready for review May 23, 2024 22:20
src/functions/Coverage.ps1 Fixed Show fixed Hide fixed
@nohwnd nohwnd changed the title Enable code coverage before P tests and stop it after Pester tests Report code coverage that includes P tests May 24, 2024
src/csharp/Sync-WithProfiler.ps1 Fixed Show fixed Hide fixed
src/csharp/Sync-WithProfiler.ps1 Fixed Show fixed Hide fixed
src/csharp/Sync-WithProfiler.ps1 Fixed Show fixed Hide fixed
@nohwnd
Copy link
Member Author

nohwnd commented May 27, 2024

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

image

@johlju
Copy link
Contributor

johlju commented May 27, 2024

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
Copy link
Member Author

nohwnd commented May 27, 2024

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
Copy link
Contributor

johlju commented May 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Measure Code Coverage for Pester
2 participants