Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| const browserEntries = new Map(); | ||
| if (shard) { | ||
| for (const p of browserProjectsToRun) { | ||
| browserEntries.set( | ||
| p.environmentName, | ||
| entriesCache.get(p.environmentName), | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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, | |
| }); | |
| } | |
| } |
Deploying rstest with
|
| Latest commit: |
c6346ab
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://038d32ea.rstest.pages.dev |
| Branch Preview URL: | https://shard.rstest.pages.dev |
There was a problem hiding this comment.
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
shardconfiguration 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.
| 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}`, |
There was a problem hiding this comment.
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."
| 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.', |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
Related Links
close: #887
Checklist