如何在Visual Studio代码(VSCode)中调试Cucumber?

时间:2017-10-19 16:08:11

标签: visual-studio-code visual-studio-debugging cucumberjs javascript-debugger

我试图在Visual Studio代码中调试Cucumber方案,并在launch.json下面进行了更改。

{
            "name": "e2e",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}\\node_modules\\.bin\\cucumber-js",
            "stopOnEntry": false,
            "args": ["--no-timeouts", "--colors"],
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": null,
            "outFiles": [
                "${workspaceRoot}\\features\\step_definitions\\*.js"
            ]
},

但是,我无法使用上述配置运行调试会话。步骤def。我在JavaScript中创建的文件。 那么,如果看起来不错,只需要上面脚本的帮助吗?

4 个答案:

答案 0 :(得分:9)

您可以尝试以下配置,使您的调试在VS Code中运行。在outFiles中提供您的要素文件路径。

{
    "name": "e2e",
    "type": "node",
    "request": "launch",
    "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber.js",
    "outFiles": [
        "${workspaceRoot}/features/*.feature"
    ]
}

<强> ============================================
更新黄瓜^ 5.0.2:

{
    "name": "NPM Cukes",
    "type": "node",
    "request": "launch",
    "console": "integratedTerminal",
    "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
    "args": [
        "path/to/features/**/*.feature",
        "-r",
        "path/to/steps/**/*",
        "--tags",
        "@your-tags"
    ]
}

如果您只想调试CURRENT功能,请将其添加到launch.json

{
    "type": "node",
    "request": "launch",
    "program": "${workspaceFolder}/node_modules/.bin/cucumber-js",
    "args": ["${relativeFile}"],
    "name": "Cukes current",
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    "windows": {
        "program": "${workspaceFolder}/node_modules/cucumber/bin/cucumber"
    }
}   

答案 1 :(得分:1)

使用Ruby时,可以在this way上使用它来运行特定的功能文件:

{
    "name": "Cucumber",
    "type": "Ruby",
    "request": "launch",
    "cwd": "${workspaceRoot}",
    "program": "${workspaceRoot}/bin/cucumber",
    "args": [
        "--tags", "@Mytags",
        ]
}

答案 2 :(得分:0)

调整Mukesh Rawat的答案,并确保其他文件路径正确无误,对我有用:

Launch.json

{
    "name": "DebugMode",
    "type": "node",
    "request": "launch",
    "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
    "args": [
        "${workspaceRoot}/features/*.feature",
        "--tags", "@debug"
    ]
}

Workspace.json

{
    "cucumberautocomplete.steps": [
        "features/steps/*.js"
    ],
    "cucumberautocomplete.syncfeatures": "features/*.feature",
    "cucumberautocomplete.strictGherkinCompletion": true,
    "settings": {},
    "folders": [
        {
            "path": "/Users/{me}/Documents/{project folder}/{project name}"
        }
    ]
}

Package.json

"scripts": {
    "debug": "node --inspect=1337 --debug-brk --nolazy node_modules/cucumber/bin/cucumber-js --tags @debug --format json:./reports/report.json",

CucumberTest.feature

@debug
Scenario: Validate I can get debug working

答案 3 :(得分:0)

这有效

{
    "name": "DebugMode",
    "type": "node",
    "request": "launch",
    "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
    "args": [
        "${workspaceRoot}/features/*.feature",
        "--tags", "@debug"
    ]
}