close

output

output.module output.moduleoutput.module

Whether to output JavaScript files in ES module format.

Rstest outputs and executes test code in CommonJS format by default. If you want to output test code in ES module format, you can enable it through the following configuration:

rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  output: {
    module: true,
  },
});

output.externals output.externalsoutput.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_modules directory, with file extensions .js, .mjs, .cjs.
  • 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.

rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  output: {
    externals: ['react'],
  },
});

If you want all dependencies to be bundled, you can configure it through the following configuration:

rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  tools: {
    rspack: (config) => {
      config.externals = [];
    },
  },
});

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:

rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  output: {
    externals: {
      lodash: 'commonjs lodash',
    },
  },
});

You can also specify the default external type for all dependencies through the externalsType configuration option.

rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  tools: {
    rspack: {
      externalsType: 'commonjs',
    },
  },
});

output.cssModules output.cssModulesoutput.cssModules

For custom CSS Modules configuration.

output.cleanDistPath output.cleanDistPathoutput.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.