【发布时间】:2019-04-01 10:58:01
【问题描述】:
我最近从 Vim 切换到 VSCode,我正在尝试为通过 docker 运行的开玩笑测试设置 VSCode 调试。
调试工作......有点。如果我想运行 Jest 测试并激活断点,我需要:
- 插入断点
- 通过下面的
vscode-jest-testslaunch.json 任务开始运行相关的笑话测试 - 在测试套件遇到断点之前快速执行
Docker: Attach To Node
显然不理想 - 我希望确保 VSCode 在运行 vscode-jest-tests 时自动附加到调试器。简而言之:在通过 Docker 运行 Jest 测试时,是否有一种简单的方法可以附加 VSCode 调试器?
这是我当前的 launch.json 和 package.json 文件。非常感谢任何帮助:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Docker: Attach to Node",
"port": 9229,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/www",
"protocol": "inspector"
},
{
"type": "node",
"request": "launch",
"name": "vscode-jest-tests",
"runtimeExecutable": "npm",
"runtimeArgs": [ "run", "test:debug" ],
"address": "127.0.0.1",
"port": 9229,
"breakOnLoad": true,
"restart": true,
"timeout": 10000,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/www",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
package.json
#...
"scripts": {
"test:debug": "docker exec -it kiva_api node --nolazy --inspect-brk=0.0.0.0:9229 node_modules/.bin/jest --runInBand --config=test/jest-e2e.json"
}
#...
PS:如果我从命令行运行 npm run test:debug 并打开一个 chrome 调试器窗口,Chrome 的调试器就可以正常工作
【问题讨论】:
标签: node.js docker debugging visual-studio-code jestjs