Skip to content

Collect code coverage in parallel runs#2860

Open
nohwnd wants to merge 1 commit into
mainfrom
nohwnd-super-tribble
Open

Collect code coverage in parallel runs#2860
nohwnd wants to merge 1 commit into
mainfrom
nohwnd-super-tribble

Conversation

@nohwnd

@nohwnd nohwnd commented Jul 10, 2026

Copy link
Copy Markdown
Member

Summary

Run.Parallel previously fell back to a sequential run (with a warning) whenever CodeCoverage was enabled. This enables coverage collection during parallel runs instead.

  • Each worker measures its own file with breakpoints and returns its per-location hits. The default profiler/tracer keeps state in a process-global static and is not concurrency-safe across worker runspaces, so breakpoint mode is forced for parallel + coverage.
  • The parent merges every worker's hits, adds the coverage of any #pester:no-parallel files it runs in-session, and lets the existing Coverage plugin End step emit the single merged report and output file (JaCoCo/Cobertura) plus run.CodeCoverage.
  • PowerShell 5.1 stays unsupported for parallel — it still falls back to a sequential run (collecting coverage sequentially) with the version warning, since it lacks ForEach-Object -Parallel.

Changes

  • src/functions/Pester.Parallel.ps1 — workers enable breakpoint coverage, suppress their own report/file write via a CodeCoverageSkipReport module flag, and return a lightweight per-location hit projection.
  • src/functions/Coverage.ps1 — new Merge-CoverageFromParallel and Convert-CommandCoverageToProjection helpers.
  • src/functions/Coverage.Plugin.ps1End step honors the skip flag and reads UseBreakpoints from the captured plugin configuration.
  • src/Main.ps1 — removes the coverage fallback/warning; collects worker coverage, measures #pester:no-parallel files in-session, merges everything, and hands it to the Coverage plugin for the single report.
  • tst/Pester.RSpec.Parallel.ts.ps1 — replaces the obsolete "falls back with warning when CodeCoverage" test with two tests: parallel coverage equals sequential, and coverage from a #pester:no-parallel file is merged in.

Verification

  • Parallel coverage matches a sequential run exactly (analyzed/executed/missed counts, percent, executed lines).
  • Mixed #pester:no-parallel case merges correctly; JaCoCo + Cobertura XML valid; output file written; no stray worker output files.
  • All 21 parallel P-tests pass (incl. 2 new coverage tests); all 12 coverage P-tests pass.
  • No new PSScriptAnalyzer custom-rule violations in the changed lines.

Related to #1704.

Run.Parallel previously fell back to sequential (with a warning) whenever
CodeCoverage was enabled. Enable coverage in parallel instead: each worker
measures its file with breakpoints (the default profiler/tracer keeps state in
a process-global static and is not concurrency-safe across runspaces) and
returns its per-location hits. The parent merges every worker's hits, adds the
coverage of any #pester:no-parallel files it runs in-session, and lets the
Coverage plugin's End step emit the single merged report and output file.

PowerShell 5.1 remains unsupported for parallel and still falls back to a
sequential run (collecting coverage sequentially) with the version warning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd added this to the 6.1.0 milestone Jul 10, 2026
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.

1 participant