|
1 |
| -# Debug mode |
| 1 | +# Debugging |
| 2 | + |
| 3 | +## Debug mode |
2 | 4 |
|
3 | 5 | Rstest provides a debug mode to troubleshoot problems, you can add the `DEBUG=rstest` environment variable when building to enable Rstest's debug mode.
|
4 | 6 |
|
5 | 7 | ```bash
|
6 | 8 | DEBUG=rstest pnpm test
|
7 | 9 | ```
|
8 | 10 |
|
9 |
| -In debug mode, Rstest will write test outputs to disk, and write the Rstest config, Rsbuild config and Rspack config to the dist directory, which is convenient for developers to view and debug. |
| 11 | +In debug mode, Rstest will: |
| 12 | + |
| 13 | +- Write test temporary outputs to disk |
| 14 | +- Write the Rstest config, Rsbuild config and Rspack config to the dist directory |
| 15 | +- Show full error stack traces |
| 16 | +- Set logger level to `verbose` |
10 | 17 |
|
11 |
| -## Rstest config file |
| 18 | +### Rstest config file |
12 | 19 |
|
13 | 20 | 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.
|
14 | 21 |
|
@@ -44,3 +51,29 @@ export default {
|
44 | 51 | ```
|
45 | 52 |
|
46 | 53 | For a complete introduction to Rstest config, please see the [Configure Rstest](/guide/basic/configure-rstest) chapter.
|
| 54 | + |
| 55 | +## Debugging in VS Code |
| 56 | + |
| 57 | +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. |
| 58 | + |
| 59 | +You can also add a dedicated launch configuration to debug a test file in VS Code: |
| 60 | + |
| 61 | +```json title=".vscode/launch.json" |
| 62 | +{ |
| 63 | + "version": "0.2.0", |
| 64 | + "configurations": [ |
| 65 | + { |
| 66 | + "name": "Debug Current Test File", |
| 67 | + "type": "node", |
| 68 | + "request": "launch", |
| 69 | + "program": "${workspaceFolder}/node_modules/@rstest/core/bin/rstest.js", |
| 70 | + "args": ["run", "${file}"], |
| 71 | + "console": "integratedTerminal", |
| 72 | + "internalConsoleOptions": "neverOpen", |
| 73 | + "skipFiles": ["<node_internals>/**"] |
| 74 | + } |
| 75 | + ] |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +Then you can start debugging the current test file directly in VS Code by pressing `F5` or go to the `Run and Debug` panel. |
0 commit comments