Skip to content

feat: support test sharding#921

Merged
9aoy merged 10 commits intomainfrom
shard
Feb 3, 2026
Merged

feat: support test sharding#921
9aoy merged 10 commits intomainfrom
shard

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Jan 29, 2026

Summary

Support shard test files for parallel execution. 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.

Usage

npx rstest --shard 1/3
import { defineConfig } from '@rstest/core';

export default defineConfig({
  shard: {
    count: 3,
    index: 1,
  },
});
image

Related Links

close: #887

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @9aoy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant new feature: test sharding. It enables users to distribute their test files across multiple parallel processes, which is particularly advantageous for accelerating test execution in continuous integration and continuous deployment (CI/CD) pipelines. The implementation provides flexible configuration through both command-line arguments and the rstest.config.ts file, ensuring broad applicability and ease of use.

Highlights

  • Test Sharding Feature: Introduced the ability to shard test files for parallel execution, primarily designed to accelerate test runs in CI/CD environments.
  • Flexible Configuration: Supports configuring test sharding via both a new CLI option (--shard <index>/<count>) and through the rstest.config.ts file (shard: { count: number, index: number }).
  • Cross-Environment Support: The sharding logic is seamlessly integrated and applied to both Node.js and browser-based test projects.
  • Robust Validation and Constraints: Includes comprehensive validation for shard parameters and prevents the use of sharding in watch mode or when configured on a per-project basis, enforcing it as a global setting.
  • New End-to-End Tests: Dedicated end-to-end tests have been added to thoroughly verify the correct behavior and functionality of the test sharding feature.
  • Comprehensive Documentation: New documentation pages for the shard option have been added in both English and Chinese, detailing its usage, configuration, and important considerations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces test sharding, a significant feature for parallelizing test execution in CI/CD environments. The implementation is comprehensive, covering CLI options, configuration, core sharding logic for both Node and Browser environments, and robust validation. New e2e tests ensure the feature works as expected, and documentation has been added to guide users. The code is well-structured, though the sharding logic in runTests.ts adds some complexity. My review includes one suggestion for improving type safety and code clarity when passing sharded entries to the browser test runner. Overall, this is a solid contribution.

Comment on lines +205 to +213
const browserEntries = new Map();
if (shard) {
for (const p of browserProjectsToRun) {
browserEntries.set(
p.environmentName,
entriesCache.get(p.environmentName),
);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The shardedEntries option on runBrowserModeTests expects a Map<string, { entries: Record<string, string> }>. Currently, you are passing the entire value from entriesCache, which may include an extra fileFilters property. While this works due to structural typing, it's cleaner and more type-safe to construct an object that precisely matches the expected type. This improves code clarity and maintainability by ensuring only the necessary data is passed.

Suggested change
const browserEntries = new Map();
if (shard) {
for (const p of browserProjectsToRun) {
browserEntries.set(
p.environmentName,
entriesCache.get(p.environmentName),
);
}
}
const browserEntries = new Map<
string,
{ entries: Record<string, string> }
>();
if (shard) {
for (const p of browserProjectsToRun) {
// The filter for `browserProjectsToRun` ensures that `entriesCache.get(p.environmentName)`
// and its `entries` property are defined.
browserEntries.set(p.environmentName, {
entries: entriesCache.get(p.environmentName)!.entries,
});
}
}

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Jan 30, 2026

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

Latest commit: c6346ab
Status: ✅  Deploy successful!
Preview URL: https://038d32ea.rstest.pages.dev
Branch Preview URL: https://shard.rstest.pages.dev

View logs

Copilot AI review requested due to automatic review settings February 3, 2026 03:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements test sharding functionality to enable parallel test execution across multiple machines or CI/CD jobs, similar to Jest's --shard option. The feature allows users to split test files into multiple shards and run them independently to reduce overall test time.

Changes:

  • Added shard configuration option with CLI support via --shard <index>/<count>
  • Implemented sharding logic that distributes test files evenly across shards with consistent sorting
  • Integrated sharding support for both node and browser mode tests
  • Added comprehensive documentation in English and Chinese
  • Included validation to prevent shard usage in watch mode and at project level

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core/src/utils/shard.ts Core sharding logic for distributing test files and resolving sharded entries
packages/core/src/cli/init.ts CLI argument parsing and validation for the --shard option
packages/core/src/cli/commands.ts Added --shard CLI option definition
packages/core/src/core/runTests.ts Integration of sharding into the main test runner for both node and browser modes
packages/core/src/core/rstest.ts Validation to prevent shard in watch mode and per-project configuration
packages/core/src/core/listTests.ts Integration of sharding into the list command
packages/core/src/core/browserLoader.ts Updated browser module interface to support sharded entries
packages/browser/src/hostController.ts Browser mode integration for sharded test execution
packages/core/src/types/config.ts Type definitions for the shard configuration option
packages/core/src/types/core.ts Added ProjectEntries type for sharded entry caching
packages/core/src/types/browser.ts Added shardedEntries option to BrowserTestRunOptions
website/docs/en/config/test/shard.mdx English documentation for the shard feature
website/docs/zh/config/test/shard.mdx Chinese documentation for the shard feature
website/docs/en/config/test/projects.mdx Updated ProjectConfig type to exclude shard
website/docs/zh/config/test/projects.mdx Updated ProjectConfig type to exclude shard
website/docs/en/config/test/_meta.json Added shard to documentation navigation
website/docs/zh/config/test/_meta.json Added shard to documentation navigation
e2e/projects/shard.test.ts Comprehensive e2e tests for sharding functionality
e2e/projects/index.test.ts Updated error handling tests to use new helper methods
e2e/list/index.test.ts Added test for list command with sharding

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +119 to +129
if (
project.config.shard &&
(project.config.shard.count !== rstestConfig.shard?.count ||
project.config.shard.index !== rstestConfig.shard?.index)
) {
logger.error(
'The `shard` option is a global option and cannot be set per-project.\n' +
'global `shard` option:\n' +
` count: ${rstestConfig.shard?.count}, index: ${rstestConfig.shard?.index}\n` +
`project "${project.config.name}" shard option:\n` +
` count: ${project.config.shard.count}, index: ${project.config.shard.index}`,
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The error message may display "count: undefined, index: undefined" when the global shard option is not set but a project has a shard config. This could be confusing. Consider updating the error message to clarify that the shard option cannot be set per-project regardless of whether it's set globally. For example: "The shard option is a global option and cannot be set per-project. Please remove the shard option from project configs."

Suggested change
if (
project.config.shard &&
(project.config.shard.count !== rstestConfig.shard?.count ||
project.config.shard.index !== rstestConfig.shard?.index)
) {
logger.error(
'The `shard` option is a global option and cannot be set per-project.\n' +
'global `shard` option:\n' +
` count: ${rstestConfig.shard?.count}, index: ${rstestConfig.shard?.index}\n` +
`project "${project.config.name}" shard option:\n` +
` count: ${project.config.shard.count}, index: ${project.config.shard.index}`,
if (project.config.shard) {
logger.error(
'The `shard` option is a global option and cannot be set per-project. ' +
'Please remove the `shard` option from project configs.',

Copilot uses AI. Check for mistakes.
9aoy and others added 2 commits February 3, 2026 11:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@9aoy 9aoy merged commit c29ec88 into main Feb 3, 2026
15 of 17 checks passed
@9aoy 9aoy deleted the shard branch February 3, 2026 05:32
@fi3ework fi3ework mentioned this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support test sharding (same as jest --shard=1/10)

2 participants