Debugging

Debug mode

Rstest provides a debug mode to troubleshoot problems, you can add the DEBUG=rstest environment variable when building to enable Rstest's debug mode.

DEBUG=rstest pnpm test

In debug mode, Rstest will:

  • Write test temporary outputs to disk
  • Write the Rstest config, Rsbuild config and Rspack config to the dist directory
  • Show full error stack traces
  • Set logger level to verbose

Rstest config file

In debug mode, Rstest will automatically generate dist/.rsbuild/rstest.config.mjs file, which contains the final generated Rstest config. In this file, you can know the final result of the Rstest config you passed in after being processed by the framework and Rstest.

The content of the file is as follows:

rstest.config.mjs
export default {
  name: 'rstest',
  include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'],
  exclude: [
    '**/node_modules/**',
    '**/dist/**',
    '**/.{idea,git,cache,output,temp}/**',
    '**/dist/.rstest-temp',
  ],
  includeSource: [],
  pool: {
    type: 'forks',
  },
  isolate: true,
  globals: false,
  passWithNoTests: false,
  update: false,
  testTimeout: 5000,
  testEnvironment: 'node',
  retry: 0,
  clearMocks: false,
  resetMocks: false,
  restoreMocks: false,
  slowTestThreshold: 300,
  // other configs...
};

For a complete introduction to Rstest config, please see the Configure Rstest chapter.

Debugging in VS Code

Rstest supports debugging in VS Code using debugger statements or breakpoints. Just open the JavaScript Debug Terminal and run the test command in the terminal.

You can also add a dedicated launch configuration to debug a test file in VS Code:

.vscode/launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Current Test File",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/@rstest/core/bin/rstest.js",
      "args": ["run", "${file}"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "skipFiles": ["<node_internals>/**"]
    }
  ]
}

Then you can start debugging the current test file directly in VS Code by pressing F5 or go to the Run and Debug panel.