--- url: https://rstest.rs/guide/start/index.md --- > For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt. # Introduction Rstest is a JavaScript testing framework powered by Rspack. It delivers comprehensive, first-class support for the Rspack ecosystem, enabling seamless integration into existing Rspack-based projects. Rstest offers full Jest-compatible APIs while providing native, out-of-the-box support for TypeScript, ESM, CJS, and more, ensuring a modern and efficient testing experience. ## ✨ Why Rstest Rstest is built on top of Rspack and Rsbuild, and works out of the box with built-in support for common use cases such as TypeScript, ESM, CJS, and CSS Modules. Even if you are not using Rspack, Rstest can be adopted without migrating your existing build system. For projects already using the Rstack toolchain (Rspack, Rsbuild, Rslib, etc.), Rstest can further **reuse your existing build configuration**—including module resolution, code transformation, and plugin capabilities—eliminating the need to maintain separate transform or resolver setups for testing. In terms of execution model, Rstest runs tests using a dependency graph–based **bundle model**, rather than the traditional per-file transform-and-execute approach. This enables it to fully leverage build-time optimizations—such as tree-shaking and skipping unused re-exports in side-effect-free barrel files—bringing test behavior closer to real production output. As a result, Rstest reduces redundant module transformations and executions in large-scale projects, improving both performance and stability. See [Module side effects](https://rstest.rs/guide/advanced/side-effects.md) for how `sideEffects` declarations affect initialization imports. By integrating testing into the build pipeline, Rstest simplifies the overall toolchain, reduces the duplicated cost of maintaining separate configuration and plugin systems, and allows testing to fit more naturally into modern engineering architectures such as monorepos and complex applications. In the future, Rstest will continue evolving around a unified “build + test” model—exploring more efficient approaches to quality assurance, and integrating more deeply with CI systems and AI-driven workflows. ## 🔥 Roadmap Rstest now supports core testing scenarios including Node / DOM testing, mocking, multi-project testing, and coverage collection, and has been successfully implemented in Rstack projects (including Rsbuild, Rslib, Rspack, and others). The project is currently in active development, and we will continue to refine functionality and enhance the user experience based on community feedback. For future development plans, please refer to the [Rstest Roadmap](https://github.com/web-infra-dev/rstest/issues/85). ## 🦀 Rstack Rstest is part of Rstack, the fast, unified JavaScript toolchain for developers and agents. ![Rstack](https://assets.rspack.rs/rstack/rstack-overview.png) Rstack includes the following tools: | Name | Description | Version | | ----------------------------------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [Rspack](https://github.com/web-infra-dev/rspack) | Bundler | npm version | | [Rsbuild](https://github.com/web-infra-dev/rsbuild) | Build tool | npm version | | [Rslib](https://github.com/web-infra-dev/rslib) | Library development tool | npm version | | [Rspress](https://github.com/web-infra-dev/rspress) | Static site generator | npm version | | [Rsdoctor](https://github.com/web-infra-dev/rsdoctor) | Build analyzer | npm version | | [Rstest](https://github.com/web-infra-dev/rstest) | Testing framework | npm version | | [Rslint](https://github.com/web-infra-dev/rslint) | Linter | npm version | | [Rstack CLI](https://github.com/rstackjs/rstack-cli) | Unified CLI | npm version | ## 📦 Core packages Rstest's base functionality is provided by [@rstest/core](https://github.com/web-infra-dev/rstest/tree/main/packages/core). Other core packages add support for Browser Mode, coverage collection, and reusing Rstack configurations. You can install them as needed for your project. Rstest includes the following core packages: | Name | Description | Version | | --------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | [@rstest/core](https://github.com/web-infra-dev/rstest/tree/main/packages/core) | Core testing framework | npm version | | [@rstest/browser](https://github.com/web-infra-dev/rstest/tree/main/packages/browser) | Browser Mode support | npm version | | [@rstest/browser-react](https://github.com/web-infra-dev/rstest/tree/main/packages/browser-react) | React component testing | npm version | | [@rstest/coverage-v8](https://github.com/web-infra-dev/rstest/tree/main/packages/coverage-v8) | V8 coverage provider | npm version | | [@rstest/coverage-istanbul](https://github.com/web-infra-dev/rstest/tree/main/packages/coverage-istanbul) | Istanbul coverage provider | npm version | | [@rstest/adapter-rsbuild](https://github.com/web-infra-dev/rstest/tree/main/packages/adapter-rsbuild) | Reuse Rsbuild config | npm version | | [@rstest/adapter-rslib](https://github.com/web-infra-dev/rstest/tree/main/packages/adapter-rslib) | Reuse Rslib config | npm version | | [@rstest/adapter-rspack](https://github.com/web-infra-dev/rstest/tree/main/packages/adapter-rspack) | Reuse Rspack config | npm version | ## 🔗 Links - [awesome-rstack](https://github.com/rstackjs/awesome-rstack): A curated list of awesome things related to Rstack. - [rstack-examples](https://github.com/rstackjs/rstack-examples): Examples showcasing Rstack tools. - [storybook-rsbuild](https://github.com/rstackjs/storybook-rsbuild): Storybook builder powered by Rsbuild. - [rsbuild-plugin-template](https://github.com/rstackjs/rsbuild-plugin-template): Use this template to create your own Rsbuild plugin. - [rstack-design-resources](https://github.com/rstackjs/rstack-design-resources): Design resources for Rstack. - [Rslint](https://rstest.rs/integration/rslint.md): Configure Rslint's built-in rules for Rstest tests. ## 🧑‍💻 Community Come and chat with us on [Discord](https://discord.gg/XsaKEEk4mW)! The Rstack team and users are active there, and we're always looking for contributions. --- url: https://rstest.rs/guide/start/quick-start.md --- > For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt. # Quick start NOTE FOR AI CODING AGENTS: Do not follow this page. Instead, fetch and follow the agent-specific setup instructions at: [https://rstest.rs/guide/start/agent-install.md](https://rstest.rs/guide/start/agent-install.md) ## Online examples You can try Rstest online without any setup by using the following examples: - [StackBlitz Example](https://stackblitz.com/~/github.com/rstackjs/rstest-stackblitz-example) ## Setup environment Before getting started, install [Node.js](https://nodejs.org/) 20.19.0 or later in the 20.x line, or 22.12.0 or later (`^20.19.0 || >=22.12.0`). We recommend an LTS version. Check the current Node.js version with the following command: ```bash node -v ``` If you do not have Node.js installed in current environment, or the installed version is too low, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install. Here is an example of how to install via nvm: ```bash # Install Node.js LTS nvm install --lts # Switch to Node.js LTS nvm use --lts ``` ## Using Rstest ### Agent prompt If you are using a coding agent, you can copy the following prompt to set up Rstest automatically: For your Agent Set up Rstest Copy Prompt Set up Rstest, the JavaScript testing framework, in this project by following the instructions here: https://rstest.rs/guide/start/agent-install.md If you are migrating from an existing Jest, Vitest, or Playwright Test project, use this prompt. Playwright Test projects migrate to `@rstest/playwright`: For your Agent Migrate to Rstest Copy Prompt Migrate this project to Rstest, the JavaScript testing framework. Detect whether it uses Jest, Vitest, or Playwright Test; for Playwright Test, migrate to @rstest/playwright. Follow the instructions here: https://rstest.rs/guide/start/agent-migrate.md ### Manual installation You can install Rstest using the following command: ```sh [npm] npm add @rstest/core -D ``` ```sh [yarn] yarn add @rstest/core -D ``` ```sh [pnpm] pnpm add @rstest/core -D ``` ```sh [bun] bun add @rstest/core -D ``` ```sh [deno] deno add npm:@rstest/core -D ``` Next, you need to update the npm scripts in your package.json to use Rstest's CLI commands. ```json title=package.json { "scripts": { "test": "rstest" } } ``` After completing the above steps, you can run the Rstest tests using `npm run test`, `yarn test`, or `pnpm test`. Alternatively, you can directly use `npx rstest` to execute the Rstest tests. Rstest has built-in commands such as `watch` and `run`, please refer to [CLI Tools](https://rstest.rs/guide/basic/cli.md) to learn about all available commands and options. ## Writing tests As a simple example, we have a `sayHi` method. To test it, you can create a test file called `index.test.ts` or use [In-Source test](https://rstest.rs/config/test/include-source.md) similar to [Rust Test](https://doc.rust-lang.org/book/ch11-03-test-organization.html#the-tests-module-and-cfgtest). ```ts title=index.ts export const sayHi = () => 'hi'; ``` ```ts title=index.test.ts import { expect, test } from '@rstest/core'; import { sayHi } from '../src/index'; test('should sayHi correctly', () => { expect(sayHi()).toBe('hi'); }); ``` Next, you can execute the test by using the command configured in [Using Rstest](#using-rstest). Rstest will print the following message: ```bash ✓ test/index.test.ts (1) Test Files 1 passed Tests 1 passed Duration 140 ms (build 17 ms, tests 123 ms) ``` ## Type checking Rstest transforms TypeScript so tests can run, but does not check types. A passing test run does not mean the project has no type errors. Run your project's type check separately. For a project with TypeScript and a `tsconfig.json`, you can add a script: ```json title="package.json" { "scripts": { "test": "rstest", "typecheck": "tsc --noEmit" } } ``` Run both `test` and `typecheck` in CI to check runtime behavior and types. ## Next steps If you want to see complete project structures, refer to these common examples: - [node](https://github.com/web-infra-dev/rstest/tree/main/examples/node): Node.js testing and coverage collection. - [react](https://github.com/web-infra-dev/rstest/tree/main/examples/react): React component, hook, and SSR tests with happy-dom. - [vue](https://github.com/web-infra-dev/rstest/tree/main/examples/vue): Vue component and SSR testing. - [browser-react](https://github.com/web-infra-dev/rstest/tree/main/examples/browser-react): React component testing in Browser Mode. For more examples, see [Rstest examples](https://github.com/web-infra-dev/rstest/tree/main/examples). --- url: https://rstest.rs/guide/start/features.md --- > For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt. # Features Rstest is a JavaScript and TypeScript testing framework built on Rsbuild and Rspack. Its bundle-based execution model uses Rspack's Rust-based build pipeline and SWC transforms for fast test compilation. Reuse your build configuration, test in Node.js or a browser, and run local development and CI workflows with the same runner. ## Fast bundle-based execution Rstest uses Rspack to bundle tests based on their dependency graph, with its built-in SWC loader transforming JavaScript and TypeScript. This brings build-time optimizations directly into the test workflow. Optimizations such as [lazyBarrel](https://rspack.rs/guide/advanced/lazy-barrel) skip unused re-exports in side-effect-free barrel files, reducing unnecessary module processing and speeding up tests in large projects with complex dependency graphs. ## Reuse existing build setup Reuse existing Rsbuild, Rslib, or Rspack configuration through [adapters](https://rstest.rs/guide/advanced/adapters.md), including aliases, transforms, and plugins. This reduces duplicate configuration and helps keep tests aligned with your application or library's build setup. See [Configuring Rstest](https://rstest.rs/guide/basic/configure-rstest.md) and [Configuring SWC](https://rstest.rs/guide/basic/configure-rstest.md#configure-swc). ## Test in Node.js and browsers Run tests in the default Node.js environment, simulate the DOM for component tests, or use a real browser when browser behavior matters. ### DOM testing Rstest can simulate the DOM and browser APIs with jsdom or happy-dom. It supports common framework testing workflows for React and Vue, and works with Testing Library and CSS Modules. Learn more about [DOM testing](https://rstest.rs/config/test/test-environment.md#dom-testing). ### Browser mode Rstest provides Browser Mode for tests that need a real browser instead of a simulated environment such as jsdom or happy-dom. This helps validate browser APIs, rendering behavior, and interactions that are difficult to cover in DOM simulators. Browser Mode is powered by [Playwright](https://playwright.dev/) and can run tests in Chromium, Firefox, and WebKit, making it suitable for cross-browser verification. Learn more about [Browser mode](https://rstest.rs/guide/browser-testing.md). ### Playwright-driven E2E tests Rstest can run E2E tests against a complete page or app with [@rstest/playwright](https://github.com/web-infra-dev/rstest/tree/main/packages/playwright). Tests run in Node.js workers and use Playwright to drive a local dev server, preview server, or deployed URL while sharing the same Rstest runner, configuration, and reporting workflow as other tests. Learn more about [E2E testing](https://rstest.rs/guide/basic/e2e-testing.md). ### Test Module Federation applications Rstest can load real [Module Federation](https://module-federation.io/) remotes in Node, JSDOM, and Browser Mode tests. With [@module-federation/rstest](https://github.com/module-federation/core), tests exercise remote loading and shared dependencies instead of replacing the federation boundary with mocks. Learn more about [Module Federation testing](https://rstest.rs/guide/advanced/module-federation.md). ## Get faster feedback ### Watch mode When you modify a test file or one of its dependencies, Rstest analyzes the module graph and only reruns the affected test files. This keeps local feedback fast as the test suite grows. ### VM mode [Added in v0.12.0](https://github.com/web-infra-dev/rstest/releases/tag/v0.12.0) For suites where worker startup and dependency compilation take a large share of the runtime, VM mode offers `vmForks` and `vmThreads` pools. They reuse child processes or worker threads while creating a fresh `vm.Context`, module graph, and test environment for each test file. VM pools can reduce repeated startup and compilation work. Setup files and module evaluation still run for every file, and process-level state is not isolated by the VM context. Start with the default `forks` pool and check VM compatibility before switching. See [Choosing a pool](https://rstest.rs/config/test/pool.md) for configuration, memory recycling, and compatibility details. ### In-source tests Rstest supports a Rust-like module testing style that lets you write test blocks directly inside source files. It works well for small utilities and helpers where keeping fast checks next to the implementation makes development easier. Learn more about [In-source tests](https://rstest.rs/config/test/include-source.md). ## Scale test runs in CI ### Multi-project testing Rstest can run multiple test projects in one process, with each project keeping its own configuration and environment. This is useful for monorepos, multi-app workspaces, and projects that need separate Node, DOM, or Browser Mode test targets. Learn more about [Test projects](https://rstest.rs/guide/basic/projects.md). ### Test sharding Rstest can split test files into shards for parallel execution. In CI, you can distribute the same test suite across multiple machines to reduce total runtime, then use the `blob` reporter and `rstest merge-reports` to merge test results and coverage data after all shards complete. Learn more about [Test sharding](https://rstest.rs/guide/basic/cli.md#sharding-tests). ### Code coverage Collect code coverage with the `istanbul` or `v8` provider, generate reports, and enforce coverage thresholds in CI. Coverage is also available in Browser Mode, with provider support depending on the browser and run mode. See [Code coverage](https://rstest.rs/config/test/coverage.md) for provider selection and configuration. ## More capabilities - [Jest-compatible assertions](https://rstest.rs/api/runtime-api/test-api/expect.md) and [snapshot testing](https://rstest.rs/guide/basic/snapshot.md) - [Mock and spy utilities](https://rstest.rs/guide/basic/mock.md) - [File-level isolation](https://rstest.rs/config/test/isolate.md) - [Lifecycle hooks for setup and teardown](https://rstest.rs/api/runtime-api/test-api/hooks.md) - [Built-in reporters and CI output](https://rstest.rs/guide/basic/reporters.md) - [Filtering by directory, project, file, or test name](https://rstest.rs/guide/basic/test-filter.md) - [VS Code extension](https://rstest.rs/guide/basic/vscode-extension.md) --- url: https://rstest.rs/guide/start/ai.md --- > For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt. # AI To help AI better understand Rstest's features, configuration, and best practices so it can provide more accurate assistance during day-to-day development and troubleshooting, Rstest provides the following capabilities: - [Agent prompt](#agent-prompt) - [Agent Skills](#agent-skills) - [llms.txt](#llmstxt) - [Markdown docs](#markdown-docs) - [Markdown reporter](#markdown-reporter) - [AGENTS.md](#agentsmd) ## Agent prompt If you are using a coding agent (such as Claude Code, Cursor, Copilot, etc.), copy the prompt that matches your project. The agent will read the linked instructions and install dependencies, create configuration, and write tests based on your project type. ### Set up Rstest Use this prompt to add Rstest to a project that doesn't have a test runner configured yet: For your Agent Set up Rstest Copy Prompt Set up Rstest, the JavaScript testing framework, in this project by following the instructions here: https://rstest.rs/guide/start/agent-install.md ### Migrate from Jest, Vitest, or Playwright Use this prompt to migrate an existing Jest, Vitest, or Playwright Test project to Rstest. Playwright Test projects migrate to `@rstest/playwright`. For convenience, the linked instructions inline the full [migrate-to-rstest](https://github.com/rstackjs/agent-skills#migrate-to-rstest) skill so nothing needs to be installed; alternatively, you can [install the skill](#agent-skills) and use it directly: For your Agent Migrate to Rstest Copy Prompt Migrate this project to Rstest, the JavaScript testing framework. Detect whether it uses Jest, Vitest, or Playwright Test; for Playwright Test, migrate to @rstest/playwright. Follow the instructions here: https://rstest.rs/guide/start/agent-migrate.md ## Agent Skills Agent Skills are domain-specific knowledge packs that can be installed into Agents, enabling them to give more accurate and professional suggestions or perform actions in specific scenarios. In the [rstackjs/agent-skills](https://github.com/rstackjs/agent-skills) repository, there are many skills for the Rstack ecosystem. The skills related to Rstest include: - [migrate-to-rstest](https://github.com/rstackjs/agent-skills#migrate-to-rstest): Migrate Jest, Vitest, or Playwright Test projects to Rstest, using `@rstest/playwright` for Playwright E2E tests. - [rstest-best-practices](https://github.com/rstackjs/agent-skills#rstest-best-practices): Share best practices for using Rstest. - [rstest-debugging](https://github.com/rstackjs/agent-skills#rstest-debugging): Debug Rstest issues systematically, including performance regressions. Use it when Rstest is slower than expected, slower than Jest or Vitest, or when you need to determine whether the bottleneck is in build startup or test execution before trying config or code changes. In Coding Agents that support skills, you can use the [skills](https://www.npmjs.com/package/skills) package to install a specific skill with the following command: ```sh [npx] npx skills add rstackjs/agent-skills --skill migrate-to-rstest ``` ```sh [yarn] yarn dlx skills add rstackjs/agent-skills --skill migrate-to-rstest ``` ```sh [pnpm] pnpm dlx skills add rstackjs/agent-skills --skill migrate-to-rstest ``` ```sh [bunx] bunx skills add rstackjs/agent-skills --skill migrate-to-rstest ``` ```sh [deno] deno run -A npm:skills add rstackjs/agent-skills --skill migrate-to-rstest ``` After installation, simply use natural language prompts to trigger the skill, for example: ``` Help me migrate this Playwright Test project to @rstest/playwright ``` ## llms.txt [llms.txt](https://llmstxt.org/) is a standard that helps LLMs discover and use project documentation. Rstest follows this standard and publishes the following two files: - [llms.txt](https://rstest.rs/llms.txt): A structured index file containing the titles, links, and brief descriptions of all documentation pages. ``` https://rstest.rs/llms.txt ``` - [llms-full.txt](https://rstest.rs/llms-full.txt): A full-content file that concatenates the complete content of every documentation page into a single file. ``` https://rstest.rs/llms-full.txt ``` You can choose the file that best fits your use case: - `llms.txt` is smaller and consumes fewer tokens, making it suitable for AI to fetch specific pages on demand. - `llms-full.txt` contains the complete documentation content, so AI doesn't need to follow individual links — ideal when you need AI to have a comprehensive understanding of Rstest, though it consumes more tokens and is best used with AI tools that support large context windows. ## Markdown docs Every Rstest documentation page has a corresponding `.md` plain-text version that can be provided directly to AI. On any doc page, you can click “Copy Markdown” or “Copy Markdown Link” under the title to get the Markdown content or link. ``` https://rstest.rs/guide/start/index.md ``` Providing the Markdown link or content allows AI to focus on a specific chapter, which is useful for targeted troubleshooting or looking up a particular topic. ## Markdown reporter When you want AI to directly consume test results, use the `md` reporter. It outputs a single markdown document to stdout, which is easier for LLMs to parse than colorful terminal logs. The output is also more concise, which usually reduces token usage. In Agent environments, Rstest defaults to `md` when you didn't explicitly configure reporters. ```bash npx rstest --reporters=md ``` You can also configure it in `rstest.config.ts` and combine it with other reporters in local or CI workflows. ```ts import { defineConfig } from '@rstest/core'; export default defineConfig({ reporters: ['md'], }); ``` More information about the `md` reporter can be found in [Markdown reporter](https://rstest.rs/guide/basic/reporters.md#markdown-reporter). ## AGENTS.md You can create an `AGENTS.md` file in the root of any project that uses Rstest. This file follows the [AGENTS.md](https://agents.md/) specification and provides key project information to Agents. Here is an example of Rstest-related content you can add to `AGENTS.md`: ```markdown wrapCode # AGENTS.md You are an expert in JavaScript, Rspack, Rsbuild, and Rstest. You write maintainable, performant, and accessible tests. ## Tools ### Rstest - Run `npm run test` to run tests (`npx rstest`) - Run `npm run test:watch` to run tests in watch mode (`npx rstest --watch`) ## Docs - Rstest: https://rstest.rs/llms.txt ``` You can also customize it for your project, adding more details about the project structure, overall architecture, and other relevant information so Agents can better understand your project. --- url: https://rstest.rs/guide/basic/cli.md --- > For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt. # CLI Rstest comes with a lightweight CLI that includes commands such as [rstest watch](#rstest-watch) and [rstest run](#rstest-run). ## rstest -h `rstest -h` can help you view all available CLI commands and options: ```bash npx rstest -h ``` The output is shown below: ```bash Usage: $ rstest [...filters] Commands: [...filters] run tests run [...filters] run tests without watch mode watch [...filters] run tests in watch mode list [...filters] lists all test files that Rstest will run merge-reports [path] Merge blob reports from multiple shards into a unified report init [project] Initialize rstest configuration Options: -h, --help Display this message -v, --version Display version number ``` Use `npx rstest -h` to see command-specific options. For example, `npx rstest init -h` only shows initialization options, while `npx rstest merge-reports -h` only shows merge-related options. ## rstest \[...filters] Running `rstest` directly will enable the Rstest test in the current directory. ```bash $ npx rstest ✓ test/index.test.ts (2 tests) 1ms Test Files 1 passed (1) Tests 2 passed (2) Duration 189 ms (build 22 ms, tests 167 ms) ``` Wrap a filter in matching single or double quotes to match an exact absolute or root-relative path; the shell removes one layer of quotes, so use two layers: ```bash rstest run '"src/foo.test.ts"' ``` ### Watch mode If you want to automatically rerun the test when the file changes, you can use the `--watch` flag or `rstest watch` command: ```bash $ npx rstest --watch ``` ## rstest run `rstest run` will perform a single run, and the command is suitable for CI environments or scenarios where tests are not required to be performed while modifying. ### Run related tests [Added in v0.10.0](https://github.com/web-infra-dev/rstest/releases/tag/v0.10.0) Use `--related` when you want Rstest to treat positional arguments as source files and only run the tests that depend on those files. ```bash npx rstest run --related src/button.ts ``` Rstest resolves related tests from the build module graph, so the same filter works for Node mode and Browser Mode projects. You can also use the Jest-compatible alias: ```bash npx rstest run --findRelatedTests src/button.ts ``` Compilation errors in files that are unrelated to the requested source do not fail `--related` or `--changed`. If a test file itself fails to compile it cannot be analyzed, so it may be missed by the selection and a warning is printed. `passWithNoTests` only permits an empty selection. If you only want to inspect the affected test files, combine it with `rstest list`: ```bash npx rstest list --related src/button.ts --filesOnly ``` `--related` and `--findRelatedTests` are not supported in watch mode, which already reruns the tests affected by your file changes. ### Run changed tests [Added in v0.10.0](https://github.com/web-infra-dev/rstest/releases/tag/v0.10.0) Use `--changed` to collect changed files from the current Git repository and run the tests related to those files. By default, it includes unstaged, staged, and untracked files, which is useful for local development before committing: ```bash npx rstest run --changed ``` You can also pass a commit or branch. Rstest will include files changed between that ref and `HEAD`, plus local staged, unstaged, and untracked files: ```bash npx rstest run --changed=HEAD~1 npx rstest run --changed=origin/main ``` When a changed file matches [`forceRerunTriggers`](https://rstest.rs/config/test/force-rerun-triggers.md), Rstest runs the whole test suite instead of only related tests. When coverage is enabled and [`coverage.changed`](https://rstest.rs/config/test/coverage.md#changed) is not configured, `--changed` also limits coverage reports to changed source files. If a changed file matches [`forceRerunTriggers`](https://rstest.rs/config/test/force-rerun-triggers.md), Rstest runs the whole test suite and reports full coverage unless `coverage.changed` is explicitly enabled. Use `rstest list` to preview which tests would run without executing them: ```bash npx rstest list --changed --filesOnly ``` `--changed` cannot be combined with positional filters or `--related` / `--findRelatedTests`, because it already provides the source-file filter from Git state. It is not supported in watch mode either. ### Run a shard \{#sharding-tests} Use `--shard /` to split test files into several shards for parallel execution. `count` is the total number of shards and `index` (1-based) is the shard to run. ```bash # Split tests into 3 shards, run the 1st shard npx rstest run --shard 1/3 ``` This is especially useful in CI/CD, where you split the suite across jobs to reduce overall test time, then merge the per-shard reports with [`rstest merge-reports`](#rstest-merge-reports). Test files are sorted by the SHA-1 hash of their path relative to the root of the Rstest run, with path separators normalized to `/`. This spreads files from the same directory across shards while keeping the result consistent across runs and checkout locations. Sharding happens during the test-file scanning phase, before the build, to optimize performance. Make sure the `count` and `index` values are valid (`1 <= index <= count`). Files are distributed evenly across shards, with any remainder assigned one file at a time to the first shards. For example, 10 files split into 3 shards produce 4, 3, and 3 files, respectively. ## rstest watch `rstest watch` will start listening mode and execute tests, and when the test or dependent file modifications, the associated test file will be re-execute. ## rstest list `rstest list` will print a test list of all matching conditions. By default, it prints the test names of all matching tests. ```bash $ npx rstest list # the output is shown below: a.test.ts > test a > test a-1 a.test.ts > test a-2 b.test.ts > test b > test b-1 b.test.ts > test b-2 ``` The `rstest list` command inherits all `rstest` filtering options, you can filter files directly or use `-t` to filter the specified test name. ```bash $ npx rstest list -t='test a' # the output is shown below: a.test.ts > test a > test a-1 a.test.ts > test a-2 ``` You can use `--filesOnly` to make it print the test files only: ```bash $ npx rstest list --filesOnly # the output is shown below: a.test.ts b.test.ts ``` You can use `--json` to make it print tests in JSON format in terminal or save the results to a separate file: ```bash $ npx rstest list --json $ npx rstest list --json=./output.json ``` You can use `--includeSuites` to print test suites along side test cases: ```bash $ npx rstest list # the output is shown below: a.test.ts > test a a.test.ts > test a > test a-1 a.test.ts > test a-2 b.test.ts > test b b.test.ts > test b > test b-1 b.test.ts > test b-2 ``` You can use `--printLocation` to print location of tests: ```bash $ npx rstest list # the output is shown below: a.test.ts:4:5 > test a > test a-1 a.test.ts:9:3 > test a-2 b.test.ts:4:5 > test b > test b-1 b.test.ts:9:3 > test b-2 ``` You can use `--summary` to append a compact summary after the list output: ```bash $ npx rstest list --summary # the output is shown below: a.test.ts > test a > test a-1 a.test.ts > test a-2 b.test.ts > test b > test b-1 b.test.ts > test b-2 c.test.ts > test c it each 0 c.test.ts > test c it for 0 c.test.ts > test c it runIf c.test.ts > test c it skipIf Test Files 3 matched Tests 8 matched ``` When used with `--json`, `--summary` changes the JSON output shape from an array to an object with `items` and `summary` fields. ## rstest merge-reports [Added in v0.9.3](https://github.com/web-infra-dev/rstest/releases/tag/v0.9.3) `rstest merge-reports` merges blob reports generated by multiple test shards into a single unified report. This is useful when running tests in parallel across multiple CI machines using [`--shard`](#sharding-tests). ### Workflow 1. Run each shard with the `blob` reporter to generate blob report files: ```bash # On CI machine 1 npx rstest run --shard 1/3 --reporters=blob # On CI machine 2 npx rstest run --shard 2/3 --reporters=blob # On CI machine 3 npx rstest run --shard 3/3 --reporters=blob ``` 2. Collect all `.rstest-reports/` directories into a single location, then merge: ```bash npx rstest merge-reports ``` By default, blob reports are read from `.rstest-reports/` in the project root. You can specify a custom path: ```bash npx rstest merge-reports ./custom-reports-dir ``` The merge command will: - Combine test results from all blobs - Run configured reporters (e.g., `default`, `junit`) with the merged data - Merge the coverage collected by all blob-producing runs (if coverage is enabled) - Apply `coverage.include` once to add files that none of those runs tested - Generate coverage reports and check thresholds against the unified result With coverage providers that support deferred finalization, runs using the blob reporter deliberately skip coverage report generation and threshold checks. Runs without the blob reporter finalize coverage normally, including sharded runs. Older providers retain their existing per-run finalization behavior. Enable coverage for `merge-reports` through your configuration or the `--coverage` flag so the merge job can finalize coverage. The merge command accepts the same `--coverage.*` options as `rstest run`. Coverage options passed only to a blob-producing run are not stored in its blob, so define finalization options such as `coverage.include`, `coverage.reporters`, and `coverage.reportsDirectory` in the configuration file or repeat them on `merge-reports`. Use `--cleanup` to remove the blob report inputs after merging. The directory is also removed when it becomes empty. If `coverage.reportsDirectory` is the blob directory or one of its subdirectories, generated coverage reports and their containing directory are retained: ```bash npx rstest merge-reports --cleanup ``` ## rstest init `rstest init` creates starter configuration for supported project types. ```bash npx rstest init ``` Currently, `browser` is the available initializer: ```bash npx rstest init browser ``` Use `--yes` to skip the interactive prompt and apply the default setup: ```bash npx rstest init browser --yes ``` ## CLI options Rstest CLI options are registered per command instead of being shared by every command. ### Test commands `rstest`, `rstest run`, and `rstest watch` share the same test runtime options, except `--related`, `--findRelatedTests`, `--changed`, and `--shard`, which are rejected in watch mode: | Flag | Description | | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `--bail [number]` | Abort the test run after the specified number of test failures, see [bail](https://rstest.rs/config/test/bail.md) | | `--browser, --browser.enabled` | Run tests in Browser Mode, see [browser](https://rstest.rs/config/test/browser.md) | | `--browser.headless` | Run browser in headless mode (default: `true` in CI), see [browser](https://rstest.rs/config/test/browser.md) | | `--browser.screenshotFailures` | Save a screenshot for each failed browser test, see [browser](https://rstest.rs/config/test/browser.md#screenshotfailures) | | `--browser.name ` | Browser to use: `chromium`, `firefox`, `webkit` (default: `chromium`), see [browser](https://rstest.rs/config/test/browser.md) | | `--browser.port ` | Port for the Browser Mode dev server, see [browser](https://rstest.rs/config/test/browser.md) | | `--browser.strictPort` | Exit if the specified port is already in use, see [browser](https://rstest.rs/config/test/browser.md) | | `--changed [commit]` | Run tests related to changed files in the current Git repository, optionally since a commit | | `--clearMocks` | Automatically clear mock calls, instances, contexts and results before every test, see [clearMocks](https://rstest.rs/config/test/clear-mocks.md) | | `-c, --config ` | Specify the configuration file, can be a relative or absolute path, see [Specify config file](https://rstest.rs/guide/basic/configure-rstest.md#specify-config-file) | | `--config-loader ` | Specify the config loader (`auto` \| `jiti` \| `native`), see [Rsbuild - Specify config loader](https://rsbuild.rs/guide/configuration/rsbuild#specify-config-loader) | | `--coverage` | Enable code coverage collection, see [coverage](https://rstest.rs/config/test/coverage.md) | | `--coverage.allowExternal` | Collect coverage for files outside the project root, see [coverage.allowExternal](https://rstest.rs/config/test/coverage.md#allowexternal) | | `--coverage.changed [commit]` | Collect coverage only for changed files in the current Git repository, optionally since a commit | | `--coverage.clean` | Clean the coverage directory before running tests, see [coverage.clean](https://rstest.rs/config/test/coverage.md#clean) | | `--coverage.enabled` | Enable code coverage collection, see [coverage.enabled](https://rstest.rs/config/test/coverage.md#enabled) | | `--coverage.exclude ` | Exclude files from coverage collection, see [coverage.exclude](https://rstest.rs/config/test/coverage.md#exclude) | | `--coverage.include ` | Include files for coverage collection, see [coverage.include](https://rstest.rs/config/test/coverage.md#include) | | `--coverage.provider ` | Choose the coverage provider (`istanbul` \| `v8`), see [coverage.provider](https://rstest.rs/config/test/coverage.md#provider) | | `--coverage.reporters ` | Specify coverage reporter(s), see [coverage.reporters](https://rstest.rs/config/test/coverage.md#reporters) | | `--coverage.reportOnFailure` | Generate coverage reports even when tests fail, see [coverage.reportOnFailure](https://rstest.rs/config/test/coverage.md#reportonfailure) | | `--coverage.reportsDirectory ` | Directory to store coverage reports, see [coverage.reportsDirectory](https://rstest.rs/config/test/coverage.md#reportsdirectory) | | `--dev.writeToDisk` | Write test temporary files to disk, see [dev.writeToDisk](https://rstest.rs/config/build/dev.md#devwritetodisk) | | `--detectAsyncLeaks` | Detect async resources that leak after tests finish, see [detectAsyncLeaks](https://rstest.rs/config/test/detect-async-leaks.md) | | `--disableConsoleIntercept` | Disable console intercept, see [disableConsoleIntercept](https://rstest.rs/config/test/disable-console-intercept.md) | | `--exclude ` | Exclude files from test, see [exclude](https://rstest.rs/config/test/exclude.md) | | `--findRelatedTests` | Alias for `--related` for Jest compatibility | | `--globals` | Provide global APIs, see [globals](https://rstest.rs/config/test/globals.md) | | `-h, --help` | Display help for command | | `--hideSkippedTestFiles` | Do not display skipped test file logs, see [hideSkippedTestFiles](https://rstest.rs/config/test/hide-skipped-test-files.md) | | `--hideSkippedTests` | Do not display skipped test logs, see [hideSkippedTests](https://rstest.rs/config/test/hide-skipped-tests.md) | | `--hookTimeout ` | Timeout of hook in milliseconds, see [hookTimeout](https://rstest.rs/config/test/hook-timeout.md) | | `--teardownTimeout ` | Time to wait for the process to exit after the run finishes, in milliseconds. 0 exits immediately. See [teardownTimeout](https://rstest.rs/config/test/teardown-timeout.md). | | `--include ` | Specify test file matching pattern, see [include](https://rstest.rs/config/test/include.md) | | `--includeTaskLocation` | Collect test and suite locations, see [includeTaskLocation](https://rstest.rs/config/test/include-task-location.md) | | `--isolate` | Run tests in an isolated environment, see [isolate](https://rstest.rs/config/test/isolate.md) | | `--logHeapUsage` | Print heap usage for each test, see [logHeapUsage](https://rstest.rs/config/test/log-heap-usage.md) | | `--maxConcurrency ` | Maximum number of concurrent tests, see [maxConcurrency](https://rstest.rs/config/test/max-concurrency.md) | | `-f, --onlyFailures` | Run only the test files that failed in the previous run, see [onlyFailures](https://rstest.rs/config/test/only-failures.md) | | `--output.cleanDistPath` | Clean test temporary files before the test starts, see [output.cleanDistPath](https://rstest.rs/config/build/output.md#outputcleandistpath) | | `--output.emitAssets` | Emit imported static assets, see [output.emitAssets](https://rstest.rs/config/build/output.md#outputemitassets) | | `--output.module` | Output JavaScript files in ES module format, see [output.module](https://rstest.rs/config/build/output.md#outputmodule) | | `--passWithNoTests` | Allows the test suite to pass when no files are found, see [passWithNoTests](https://rstest.rs/config/test/pass-with-no-tests.md) | | `--pool ` | Shorthand for `--pool.type`, see [pool](https://rstest.rs/config/test/pool.md) | | `--pool.execArgv ` | Additional Node.js execArgv for worker processes (repeatable), see [pool](https://rstest.rs/config/test/pool.md) | | `--pool.maxWorkers ` | Maximum number or percentage of workers, see [pool](https://rstest.rs/config/test/pool.md) | | `--pool.memoryLimit ` | Memory recycling threshold for `forks` with `isolate: false` (RSS) and VM pools (V8 heap), see [pool](https://rstest.rs/config/test/pool.md#poolmemorylimit) | | `--pool.type ` | Specify the test pool type, see [pool](https://rstest.rs/config/test/pool.md) | | `--printConsoleTrace` | Print console traces when calling any console method, see [printConsoleTrace](https://rstest.rs/config/test/print-console-trace.md) | | `--project ` | Only run tests for the specified project, see [Filter by project name](https://rstest.rs/guide/basic/test-filter.md#filter-by-project-name) | | `--related` | Treat positional arguments as source file paths and only run related tests | | `--reporters, --reporter ` | Specify the test reporter(s), see [reporters](https://rstest.rs/config/test/reporters.md) | | `--resetMocks` | Automatically reset mock state before every test, see [resetMocks](https://rstest.rs/config/test/reset-mocks.md) | | `--restoreMocks` | Restore spied object methods before every test, see [restoreMocks](https://rstest.rs/config/test/restore-mocks.md) | | `--retry ` | Number of times to retry a test if it fails, see [retry](https://rstest.rs/config/test/retry.md) | | `-r, --root ` | Specify the project root directory, see [root](https://rstest.rs/config/test/root.md) | | `--shard ` | Split tests into several shards, see [sharding](#sharding-tests) | | `--silent [value]` | Silence intercepted test console output, or keep logs only for failed tasks with `passed-only`, see [silent](https://rstest.rs/config/test/silent.md) | | `--slowTestThreshold ` | The number of milliseconds after which a test or suite is considered slow, see [slowTestThreshold](https://rstest.rs/config/test/slow-test-threshold.md) | | `--source.tsconfigPath ` | Path to the tsconfig.json file, see [source.tsconfigPath](https://rstest.rs/config/build/source.md#sourcetsconfigpath) | | `--testEnvironment ` | The environment that will be used for testing, see [testEnvironment](https://rstest.rs/config/test/test-environment.md) | | `-t, --testNamePattern ` | Run only tests with a name that matches the regex, see [testNamePattern](https://rstest.rs/config/test/test-name-pattern.md) | | `--testTimeout ` | Timeout of a test in milliseconds, see [testTimeout](https://rstest.rs/config/test/test-timeout.md) | | `--trace` | Dump a Perfetto-compatible performance trace JSON file, plus a ranked markdown timing summary printed to the terminal and written next to it, see [Using --trace](https://rstest.rs/guide/debug/profiling.md#using-trace) | | `--unstubEnvs` | Restores all `process.env` values that were changed with `rs.stubEnv` before every test, see [unstubEnvs](https://rstest.rs/config/test/unstub-envs.md) | | `--unstubGlobals` | Restores all global variables that were changed with `rs.stubGlobal` before every test, see [unstubGlobals](https://rstest.rs/config/test/unstub-globals.md) | | `-u, --update` | Update snapshot files, see [update](https://rstest.rs/config/test/update.md) | `rstest` also supports `-w, --watch`, which switches the default command into watch mode. ### rstest list `rstest list` supports the same filtering and config options as the test commands above, and adds: | Flag | Description | | ----------------------- | ------------------------------------------- | | `--filesOnly` | Only print matching test files | | `--json [boolean/path]` | Print tests as JSON or write JSON to a file | | `--includeSuites` | Include suites in the output | | `--printLocation` | Print test and suite locations | | `--summary` | Print a compact summary after the list | ### rstest merge-reports `rstest merge-reports` has its own smaller option set: | Flag | Description | | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `-c, --config ` | Specify the configuration file, can be a relative or absolute path, see [Specify config file](https://rstest.rs/guide/basic/configure-rstest.md#specify-config-file) | | `--config-loader ` | Specify the config loader (`auto` \| `jiti` \| `native`), see [Rsbuild - Specify config loader](https://rsbuild.rs/guide/configuration/rsbuild#specify-config-loader) | | `-r, --root ` | Specify the project root directory, see [root](https://rstest.rs/config/test/root.md) | | `--coverage` | Enable coverage generation after merging, see [coverage](https://rstest.rs/config/test/coverage.md) | | `--reporters ` | Specify which reporter(s) run on merged results, see [reporters](https://rstest.rs/config/test/reporters.md) | | `--cleanup` | Remove blob report inputs after merging | | `-h, --help` | Display help for command | ### rstest init `rstest init` only accepts initialization-specific options: | Flag | Description | | ------------ | ------------------------------------------- | | `--yes` | Use default options and skip interactive UI | | `-h, --help` | Display help for command | ### Boolean option negation For boolean options, you can use the `--no-