Skip to content

Commit 1fa7141

Browse files
9aoyCopilot
andauthored
docs: add debugging in VS Code (#530)
Co-authored-by: Copilot <[email protected]>
1 parent c65f4ca commit 1fa7141

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["debug-mode", "profiling"]
1+
["debugging", "profiling"]

website/docs/en/guide/advanced/debug-mode.mdx renamed to website/docs/en/guide/advanced/debugging.mdx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
# Debug mode
1+
# Debugging
2+
3+
## Debug mode
24

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

57
```bash
68
DEBUG=rstest pnpm test
79
```
810

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`
1017

11-
## Rstest config file
18+
### Rstest config file
1219

1320
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.
1421

@@ -44,3 +51,29 @@ export default {
4451
```
4552

4653
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.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["debug-mode", "profiling"]
1+
["debugging", "profiling"]

website/docs/zh/guide/advanced/debug-mode.mdx renamed to website/docs/zh/guide/advanced/debugging.mdx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
# 开启调试模式
1+
# 调试
2+
3+
## 开启调试模式
24

35
为了便于排查问题,Rstest 提供了调试模式,你可以在执行构建时添加 `DEBUG=rstest` 环境变量来开启 Rstest 的调试模式。
46

57
```bash
68
DEBUG=rstest pnpm test
79
```
810

9-
在调试模式下,Rstest 会将测试中间产物输出到磁盘,并将内部最终生成的 Rstest 配置、Rsbuild 配置和 Rspack 配置写入到产物目录下,便于开发者查看和调试。
11+
在调试模式下,Rstest 会:
12+
13+
- 将测试中间产物输出到磁盘
14+
- 将最终生成的 Rstest 配置、Rsbuild 配置和 Rspack 配置写入到产物目录下
15+
- 打印出完整的错误栈信息
16+
- 将日志级别设置为 `verbose`
1017

11-
## Rstest 配置文件
18+
### Rstest 配置文件
1219

1320
在调试模式下,Rstest 会自动生成 `dist/.rsbuild/rstest.config.mjs` 文件,这里面包含了最终生成的 Rstest 配置。在这个文件里,你可以了解到你传入的 Rstest 配置在经过框架层和 Rstest 处理后的最终结果。
1421

@@ -44,3 +51,29 @@ export default {
4451
```
4552

4653
关于 Rstest 配置项的完整介绍,请查看[配置 Rstest](/guide/basic/configure-rstest) 章节。
54+
55+
## 在 VS Code 中调试
56+
57+
Rstest 支持通过 `debugger` 语句或断点的方式在 VS Code 中进行调试。只需打开 `JavaScript Debug Terminal`,然后在终端中运行测试命令即可。
58+
59+
你也可以添加一个启动配置来调试当前打开的测试文件:
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+
之后,你可以直接在 VS Code 中按下 `F5` 键或前往 `Run and Debug` 面板来启动调试。

0 commit comments

Comments
 (0)