close

shard

  • Type: { count: number; index: number }
  • Default: undefined
  • CLI: --shard <index>/<count>

Shards test files for parallel execution. count represents the total number of shards, and index represents the index of the current shard (1-based).

This option can only be set at the root level of your configuration, not within individual projects.

This is particularly useful for parallelizing tests in CI/CD environments, allowing you to split the test suite into multiple parts and run them independently across different jobs, thereby reducing overall test time.

Important Notes
  • When using the --shard option, ensure that the count and index values are valid.
  • Test files will be sorted by their path to ensure consistent sharding across different runs.
  • Sharding occurs during the test file scanning phase, prior to the build process, to optimize performance.
CLI
rstest.config.ts
# Split tests into 3 shards, run the 1st shard
npx rstest --shard 1/3

Merging shard reports

When using sharding in CI, each shard produces its own test report and coverage data independently. To combine the results from all shards into a single report, use the blob reporter along with the rstest merge-reports command.

Step 1: run shards with blob reporter

Configure each shard to output results using the blob reporter:

# Shard 1
npx rstest run --shard 1/3 --reporter=blob --coverage

# Shard 2
npx rstest run --shard 2/3 --reporter=blob --coverage

# Shard 3
npx rstest run --shard 3/3 --reporter=blob --coverage

Each shard writes its results to .rstest-reports/blob-{index}-{count}.json.

Step 2: merge reports

After all shards complete, collect all blob files into a single .rstest-reports/ directory and run:

npx rstest merge-reports --cleanup

This will merge all test results, generate a unified summary using your configured reporters, and combine coverage data.

See the CLI documentation for more details on the merge-reports command.