visual-studio-code - 如何使用 Visual Studio Code 调试 CucumberJS 脚本

标签 visual-studio-code cucumberjs

我正在使用 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 testnpm 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/

相关文章:

css - 修复警告 "Also define the standard property ' box-shadow' 以实现兼容性”

cucumber - 试图运行 cucumber 但出现此错误

javascript - 如何使用回调将 cucumber 测试标记为 Node 中的待处理

protractor - 如何配置 Protractor 以使用 Cucumber

javascript - 嵌套 promise 返回未定义

c++ - Visual Studio代码: How to configure includePath for better IntelliSense results

angular - 如何在 VS 代码中发布 Angular 和 dotnet Web api 项目

linux - 在我喜欢的编辑器中打开并编辑来自远程服务器的代码文件?

visual-studio-code - vscode - 有没有办法创建 `vscode.TextDocument` 的实例?

javascript - cucumber 表达式 : How do I have strict, 多词替代文本?