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.cssModules
output.cssModules
For custom CSS Modules configuration.
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.