VSCode 调试配置
如何直接调试当前打开的 TypeScript 文件?
- 前置: 安装
tsx; - 配置: 把
runtimeExecutable指向项目内的tsx,program指向${file};
{
"type": "node",
"request": "launch",
"name": "core",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
"program": "${file}",
"cwd": "${fileDirname}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "node_modules/**"]
}
- 效果: 无需预编译, 直接运行并断点调试当前文件;
如何调试当前打开的测试文件?
- 配置: 以
vitest.mjs作为入口, 用args传入run与当前文件;
{
"type": "node",
"request": "launch",
"name": "Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
}
${relativeFile}: 当前打开文件相对工作区的路径, 只跑这一个测试文件;autoAttachChildProcesses: 自动附加到测试运行派生的子进程;