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

How to debug Cucumber in Visual Studio Code (VSCode)?

我试图在 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"
            ]
},

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

您可以尝试以下配置以使您的调试在 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"
    ]
}

如果您只想调试当前功能,请将此添加到 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"
    }
}   

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

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

调整 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

这个有效

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