Debugging
Debug mode
Enable debug mode with the DEBUG=rstest environment variable (comma-separated values containing rstest, rsbuild, builder, or * are accepted, case-insensitively):
In debug mode, Rstest:
- Writes temporary test build outputs to disk
- Writes the resolved Rstest, Rsbuild, and Rspack configs to disk
- Prints full error stack traces
- Sets logger level to
verboseand disables terminal screen clearing in watch mode
Rstest config file
In debug mode, Rstest writes the resolved configs to dist/.rstest-temp/.rsbuild/ (or <output.distPath.root>/.rsbuild/ if configured):
rstest.config.mjs: resolved Rstest configrsbuild.config.mjs: generated Rsbuild configrspack.config.<project>.mjs: generated Rspack config for each project (for example,rspack.config.rstest.mjs)
For the default configuration, dist/.rstest-temp/.rsbuild/rstest.config.mjs looks similar to:
See Configure Rstest for all configuration options.
View test temporary outputs
In debug mode or when dev.writeToDisk is enabled, Rstest writes compiled test bundles and source maps to dist/.rstest-temp (or output.distPath.root).
Inspect bundle coverage
If a Node.js test bundle is larger than expected, enable V8 coverage and set DEBUG=rstest:bundle-coverage to inspect which generated files the test runner received and which parts executed:
Rstest writes .rstest/bundle-coverage-<timestamp>.json under the project root and prints its path. For each test file, assets records the byte size of each generated file, and rawV8 records V8 execution ranges before source-map remapping. Pass a test file filter to rstest run to inspect a single bundle.
A dependency fully replaced by rs.mock() can still be bundled. Use output.externals to exclude it from the bundle.
If your coding agent supports skills, install rstest-debugging and use the prompt below:
Copy this prompt and send it to your coding agent.
Debugging test workers
Rstest strips --inspect* and --debug-port flags passed to the host node process before spawning workers so worker ports do not collide. Running node --inspect ./node_modules/@rstest/core/bin/rstest.js only attaches the debugger to the main Rstest process.
To attach a Node.js inspector to a test worker, pass --inspect-brk through pool.execArgv, limit execution to one worker with --pool.maxWorkers=1, and disable timeouts with --testTimeout=0:
When pool.execArgv includes --inspect* (or the host process itself is being inspected), Rstest automatically configures inline source maps (inline-nosources-source-map) and splits chunks to 1 MB so breakpoints resolve cleanly to your test source files.
Debugging browser mode
To inspect DOM state, console output, or browser DevTools during Browser Mode tests, run with --browser.headless=false to open a visible browser window:
When browser.headless is true (the default in CI), Rstest saves a PNG screenshot under .rstest/screenshots/ on test failure unless browser.screenshotFailures is disabled.
Debugging async leaks and memory
- Pass
--detectAsyncLeaksto fail test files that leave active async resources (such as unclosed timers) behind and report their creation stacks. SeedetectAsyncLeaks. - Pass
--logHeapUsageto print V8heapUsedafter each test file and test case in Node.js pools. SeelogHeapUsage.
Debugging in VS Code
You can debug tests in VS Code using debugger statements or editor breakpoints by opening a JavaScript Debug Terminal and running your test command there.
To debug the current test file with F5 or the Run and Debug panel, add a launch configuration to .vscode/launch.json: