Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
2 min readTesting

Shard Playwright in CI, merge one report

Run Playwright in four CI jobs, keep each blob report, and turn them into one HTML report even when tests fail.

Your Playwright suite takes up the whole test job. You can split it across four jobs, but four HTML reports make failures harder to find. Have the jobs produce blob reports and build the HTML report after they finish.

Run one shard per job

Give each job a different SHARD_INDEX, from 1 through 4. Start them from the same commit, with the same Playwright version, test configuration and browser projects. In each job, run this from the test project's directory.

pnpm exec playwright test --shard="$SHARD_INDEX/4" --reporter=blob

Each job runs its share of the suite and writes a ZIP in blob-report/. Copy that ZIP before invoking the blob reporter again in the same workspace. The reporter clears its output directory on each run. With one job per index, the four jobs cover the entire suite. A shard can contain several workers. The shard controls which tests the job receives, and the workers control concurrency within that job.

Playwright's sharding guide describes how it assigns work. With fullyParallel enabled it can divide individual tests. Otherwise it divides files, so one long spec file can leave one job running after the others finish. Check the per-job times before changing the number of shards.

diagram

Four jobs, one report

Each shard job uploads one blob ZIP, and the merge job reads all four to build one HTML report.

Collect the ZIPs after all four jobs

Upload the ZIP from each job as an artifact with a distinct name, such as blob-1 through blob-4. Configure uploads to run after test failures too. You'll want the report when a test fails, and the test command's exit code should still fail the job.

Give the merge job a dependency on all four jobs. Make it eligible to run when a test fails. Download the four artifacts and place their ZIP files directly in one directory called all-blob-reports. Check that all four are present before merging. A cancelled job or failed artifact upload can leave a gap even when the report command accepts the other files.

pnpm exec playwright merge-reports --reporter=html ./all-blob-reports

The command writes an HTML report in playwright-report/ with results from the ZIPs you supplied. Upload that directory as the artifact people open. Keep all jobs on the same runner OS for this setup, so the reports use the same test path conventions.

Before switching over, introduce a failing assertion on a test branch. Check that the shard job fails, its blob still uploads, and you can find that failure in the merged report. That run tests the part of the CI wiring you need when a suite goes red.