我正在使用 Visual Studio Code 构建 cucumber 测试。我能够从命令行使用 npm 运行测试,并且能够使用启动配置从 VS Code 中运行它们。
但是,我无法从 Visual Studio Code 中调试测试。这是在 Windows 7 上,使用 VSCode 1.12.1
基本文件结构:
.
+-- .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)。
最佳答案
我能够让它与这个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 上完成的)
关于visual-studio-code - 如何使用 Visual Studio Code 调试 CucumberJS 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43878772/