我正在使用Visual Studio代码构建cucumberjs测试。我能够从命令行使用npm运行测试,并且能够使用启动配置从VS Code中运行它们。
但是,我无法从Visual Studio代码中调试该测试。这是在装有VSCode 1.12.1的Windows7上
基本文件结构:
.
+-- .vscode
| +-- launch.json
+-- features
| +-- step_definitions
| | +-- sampleSteps.js
| +-- support
| | +-- customWorld.js
| +-- sampletest.feature
+-- node_modules
| +-- .bin
| | +-- cucumberjs
+-- package.json
+-- README.md在package.json中,我有以下内容:
"scripts": {
"test": "./node_modules/.bin/cucumberjs"
},在命令行中,我可以成功地运行npm test或npm run-script test。我有一个如下的launch.json配置:
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"windows": {
"runtimeExecutable": "npm.cmd"
},
"runtimeArgs": [
"run-script",
"test"
]
}
]
}当我在VS Code中运行调试器时,它只是运行测试,给出结果,但不支持断点。
我希望能够单步执行我的代码,而launch.json似乎就是这样做的工具。我尝试过直接从launch.json调用cucumber,但在这种情况下,它似乎找不到所有正确的文件(包括cucumberjs)。
发布于 2017-06-21 03:03:33
我能够用这个launch.json让它工作:
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Via NPM",
"runtimeExecutable": "npm",
"windows": {
"runtimeExecutable": "npm.cmd"
},
"env":{
"NODE_PATH": "test/"
},
"runtimeArgs": [
"run-script",
"debug"
],
"port": 5858
}
]
}然后在package.json中:
"scripts": {
"debug": "node --debug-brk=5858 ./node_modules/cucumber/bin/cucumber.js --profile TEST -t '@my_tag'"
}希望这能有所帮助!(请注意,这是在MacOS上完成的)
发布于 2020-08-20 14:08:29
或者只需在Windows10/ VSCode中使用它
launch.json
{
"type": "node",
"request": "launch",
"name": "Cucumber Tests",
"program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
"internalConsoleOptions": "openOnSessionStart",
}或者,如果是Mac OS,请将程序替换为以下内容
"program": "${workspaceRoot}/node_modules/.bin/cucumber-js",您不需要在
package.json
中添加scripts
https://stackoverflow.com/questions/43878772
复制相似问题