Testing with Rstest
Rstest is a JavaScript testing framework powered by Rspack. It runs tests through Rspack's bundling pipeline, and its official adapter can reuse module resolution, transforms, and plugins from an existing Rspack configuration.
This guide covers unit testing with Rstest and end-to-end testing with @rstest/playwright.
Set up Rstest
Create a new project
When creating a project, follow the Quick start guide and select Rstest - testing in the prompts. The generated project includes the Rstest dependencies, configuration, and test scripts.
Add Rstest to an existing project
Install Rstest and the official Rspack adapter as development dependencies:
Then add scripts for running tests and watching for changes:
Reuse the Rspack configuration
Create an rstest.config.ts file in the project root and use withRspackConfig to reuse the existing Rspack configuration:
The adapter loads rspack.config.ts, maps compatible Rspack options to Rstest, and merges them with the rest of the Rstest configuration.
By default, the adapter looks for the Rspack configuration in process.cwd(). It also disables Rstest's built-in CSS plugins so that the Rspack CSS configuration takes effect. For monorepos, custom configuration paths, named configurations, and complete mapping details, see Rstest - Rspack integration.
Unit testing
Unit tests verify individual modules and functions in isolation.
Write tests
Create a source file and a corresponding test file:
Run tests
See the Rstest documentation for test APIs, mocking, snapshots, coverage, and other features.
End-to-end testing
@rstest/playwright is Rstest's Playwright integration. It provides Playwright-style assertions and fixtures for testing local, preview, or deployed applications while sharing Rstest's runner, configuration, and reporting workflow with unit tests.
If you need the full Playwright Test runner and its playwright.config.ts configuration model, use native Playwright.
Install @rstest/playwright
Install the Rstest integration and the Playwright browser automation runtime:
Then install the Chromium browser binary:
Test a running application
Import test and expect from @rstest/playwright and navigate to the application served by Rspack:
Test local build output
Use Rstest's serve fixture to start a static application from local files. The server is cleaned up automatically after the test:
End-to-end tests use the Rstest runner, so they can live alongside unit tests and run with the same command:
For more fixtures, browser options, tracing, and debugging, see Rstest - Playwright.

