> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Debugging

## Debug mode

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

```bash
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/.rstest-temp/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:

```js title="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](/guide/basic/configure-rstest.md) chapter.

## View test temporary outputs

In the [debug mode](#debug-mode) or when [dev.writeToDisk](/config/build/dev.md#devwritetodisk) is enabled, Rstest will write test temporary outputs to disk. You can view the files in `dist/.rstest-temp` directory to help you troubleshoot problems.

## 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:

```json title=".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.
