Learning center

A merged test report can be missing a shard

When tests run in shards, compare the number of reports merged with the number of shards started. In Playwright, merging an incomplete set succeeded and printed a normal summary, with the missing shard's failures absent.

The merge exits 0#

The fixture has seven tests in two shards. Each shard fails one test and exits 1. Merging both blob reports with Playwright 1.65:

  2 failed
  1 flaky
  2 skipped
  2 passed

After the second shard's file was left out of the directory:

  1 failed
  1 flaky
  2 skipped
  1 passed

Both merges exited 0. So two separate facts are lost: that a shard is missing, and that tests failed. The command builds a report and does not judge it. Playwright's sharding guide runs the merge in a job of its own, after the test jobs, and the status that gates your merge has to come from the test jobs.

How a shard goes missing#

  • The job was cancelled or the machine was lost before the upload.
  • The upload step runs only on success, so a failing shard, the one you need, uploads nothing.
  • Two shards wrote the same artifact name.
  • An artifact from an earlier attempt of the run is in the directory.
  • The matrix has four entries and the command still says --shard=1/3.

The last one leaves a complete set of files with some tests run twice or not at all, so counting files alone is not enough.

Check completeness#

Write the expected total before the shards run, from the same commit and configuration:

npx playwright test --list --reporter=json > list.json
jq '[.. | objects | select(.tests? and .title?) | .tests[]] | length' list.json

Then count in the merged JSON report in the same way. Three numbers belong in the handoff:

NumberExample
Shards started, reports merged4, 4
Tests listed, tests in the merged report1,204, 1,204
Shard jobs that exited non-zero1 of 4

Equal totals do not prove that the same tests ran. A renamed test and a new test cancel out. Compare the sorted titles when the totals matter for a release decision.

Make the gate refuse#

  1. Upload with a condition that also runs on failure, and fail the upload step when the file is absent.
  2. Include the run attempt in the artifact's name.
  3. In the merge job, count the files and exit non-zero when they differ from the matrix size.
  4. Gate on the test jobs' results as well as on the report.

Worked example#

This example is fictional. A handoff links an HTML report with 903 passed and no failures. The suite has 1,204 tests. Shard 3 had run out of memory and uploaded nothing, and its job was marked as allowed to fail. Ben reruns that shard. It fails four tests in the area the release changes. The linked report was accurate for what it held, and nothing on the page said that a quarter of the suite was absent.

Within one report, retries can be hidden too. Return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading