output
output.module
output.module
- Type:
boolean - Default:
true
Whether to output JavaScript files in ES module format.
Rstest outputs and executes test code in ES module format by default. If you want to output test code in CommonJS format, you can enable it through the following configuration:
Commonjs interop
When you output JavaScript files in ES module format (output.module: true), Rstest will determine the type of external based on how the dependency is imported:
- Dependencies imported via
importsyntax will be treated as ES module type externals. - Dependencies imported via
requiresyntax will be treated as CommonJS externals.
When you import CommonJS modules using the import syntax, Rstest will attempt interop handling, allowing you to import CommonJS module exports normally using import syntax. The following code works correctly in Rstest:
However, this interop handling does not always work perfectly, depending on the way the CommonJS module exports its content. Currently, Rstest does not support interop CommonJS module default exports as named exports.
If you encounter issues during usage, you can specify the external type of a dependency as CommonJS through specifying external type.
output.externals
output.externals
Prevent some import dependencies from being packed into bundles in your code, and instead Rstest will import them at runtime.
- In the Node.js test environment, Rstest will bundle and transpile the following files by default:
- Any TypeScript and JSX files in any directory, with file extensions
.ts,.tsx,.jsx,.mts,.cts. - JavaScript files outside the
node_modulesdirectory, with file extensions.js,.mjs,.cjs.
- Any TypeScript and JSX files in any directory, with file extensions
- In the browser-like (jsdom, etc) test environment, all packages are bundled by default.
If you want a dependency to be externalized, you can configure it in output.externals.
If you want all dependencies to be bundled, you can configure it through the following configuration:
Specify external type
You can use ${externalsType} ${libraryName} syntax to specify the external type of a dependency.
For example, you can use commonjs lodash to specify that lodash should be externalized as a CommonJS module:
You can also specify the default external type for all dependencies through the externalsType configuration option.
output.bundleDependencies
- Type:
boolean - Default: Depends on
testEnvironment
Controls whether third-party dependencies from node_modules are bundled or externalized.
true: Always bundle all third-party dependencies, regardless of test environment.false: Always externalize third-party dependencies, regardless of test environment.
When this option is unset, Rstest bundles dependencies in browser-like test environments (jsdom, happy-dom, etc.), and externalizes them in the node environment.
This option only applies to non-browser mode. In browser mode, all dependencies are always bundled, so output.bundleDependencies: false is not supported.
This option provides a simple way to override the default bundling strategy that is tied to testEnvironment. For example, if you use jsdom but want the same externalization behavior as the node environment:
Or if you want to bundle all dependencies in the node environment to benefit from optimizations like lazy barrel:
Relationship with output.externals
output.bundleDependencies controls the overall bundling strategy for all node_modules dependencies, while output.externals allows fine-grained control over individual packages. When both are configured, output.externals takes higher priority:
bundleDependencies: true+externals: ['lodash']: Bundle all dependencies, but externalizelodash.bundleDependencies: false+externalsis not needed, since all dependencies are already externalized.
output.cssModules
output.cssModules
For custom CSS Modules configuration.
output.emitAssets
output.emitAssets
- Type:
boolean - Default:
true
Controls whether imported static assets such as images, fonts, audio, and video are emitted as build assets during test builds.
Rstest forwards this option to the underlying Rsbuild pipeline and follows the same behavior as Rsbuild. When output.emitAssets is true, imported asset modules are emitted into the build output file system. When it is false, those asset files are not emitted.
In Rstest, emitted assets are written to disk only when dev.writeToDisk is enabled or when you run with DEBUG output enabled. Otherwise, they stay in the temporary in-memory output used by the test build.
This option is mainly useful when you want Rstest to match an existing Rsbuild setup, or when your tests do not need to validate emitted static assets.
If you are already reusing your Rsbuild config through @rstest/adapter-rsbuild, output.emitAssets is inherited automatically.
output.distPath
output.distPath
- Type:
string | { root?: string } - Default:
{ root: 'dist/.rstest-temp' }
Control the global root directory where Rstest places its temporary build outputs.
By default, Rstest does not write test temporary files to disk. When you enable the dev.writeToDisk option or run in DEBUG mode, Rstest will write temporary artifacts to disk, outputting them to the dist/.rstest-temp directory. This includes compiled artifacts used by the Node.js test runtime, as well as temporary resources generated in browser mode such as runner files and virtual manifests.
In multi-project runs, Rstest still uses one global output root. It may create subdirectories under that root for different projects, but the base directory itself is shared and does not switch to each project's root.
If you want these files to go to another directory, set output.distPath.root:
After this change, rstest will use <root>/custom/.rstest-temp as the temporary output root instead of <root>/dist/.rstest-temp.
output.cleanDistPath
output.cleanDistPath
Whether to clean up all test temporary files under the output directory before the test starts.
By default, rstest does not write test temporary files to disk, and this configuration item may be required when you debug rstest outputs.