为了便于排查问题,Rstest 提供了调试模式,你可以在执行构建时添加 DEBUG=rstest 环境变量来开启 Rstest 的调试模式。
DEBUG=rstest pnpm test在调试模式下,Rstest 会:
verbose在调试模式下,Rstest 会自动生成 dist/.rsbuild/rstest.config.mjs 文件,这里面包含了最终生成的 Rstest 配置。在这个文件里,你可以了解到你传入的 Rstest 配置在经过框架层和 Rstest 处理后的最终结果。
该文件的大致内容如下:
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...
};关于 Rstest 配置项的完整介绍,请查看配置 Rstest 章节。
Rstest 支持通过 debugger 语句或断点的方式在 VS Code 中进行调试。只需打开 JavaScript Debug Terminal,然后在终端中运行测试命令即可。
你也可以添加一个启动配置来调试当前打开的测试文件:
{
"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>/**"]
}
]
}之后,你可以直接在 VS Code 中按下 F5 键或前往 Run and Debug 面板来启动调试。