close

source

Options for input source code.

source.decorators source.decoratorssource.decorators

Used to configure the decorators syntax.

If you are using TypeScript's experimentalDecorators, you should set source.decorators.version to legacy in this case.

source.assetsInclude source.assetsIncludesource.assetsInclude

Specify additional files that should be treated as static assets.

This is useful when your tests import file types that are not included in Rsbuild's default asset handling, such as .txt or .md.

import { defineConfig } from '@rstest/core';

export default defineConfig({
  source: {
    assetsInclude: /\.(txt|md)$/,
  },
});

If you already reuse Rsbuild or Rslib config through @rstest/adapter-rsbuild or @rstest/adapter-rslib, source.assetsInclude will be inherited automatically.

source.define source.definesource.define

Replaces variables in your code with other values or expressions at compile time. This can be useful for injecting env variables and other information to the code during build time.

source.exclude source.excludesource.exclude

Exclude JavaScript or TypeScript files that do not need to be transformed by SWC.

Note

Files configured in source.exclude will not be transformed by SWC, but the referenced files will still be bundled into the outputs.

If you want certain files not to be bundled into the outputs, you can use output.externals or Rspack's IgnorePlugin.

source.include source.includesource.include

Specify additional JavaScript files that need to be compiled.

source.transformImport source.transformImportsource.transformImport

Configure on-demand import transforms.

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

export default defineConfig({
  source: {
    transformImport: [
      {
        libraryName: 'demo-lib',
        libraryDirectory: '.',
        camelToDashComponentName: false,
      },
    ],
  },
});
Caution

source.transformImport rewrites the final module request at compile time.

In the current implementation, module-level mocking APIs that still use the original specifier, such as rs.mock('pkg'), rs.doMock('pkg'), rs.importActual('pkg'), and rs.requireActual('pkg'), may no longer target the transformed module request.

source.tsconfigPath source.tsconfigPathsource.tsconfigPath

Configure a custom tsconfig.json file path to use, can be a relative or absolute path.