Search code examples
visual-studio-codevisual-studio-debuggingcucumberjsjavascript-debugger

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


I was trying to debug Cucumber scenarios in Visual Studio code and made below changes in the 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"
            ]
},

However, I am not able run a debug session using the above configuration. The step def. files I created in JavaScript. So, just need a help on the script above if that looks fine?


Solution

  • You could try below configuration to make your debug working in VS Code. In the outFiles give your feature file path.

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

    ============================================
    UPDATE AS OF cucumber ^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"
        ]
    }
    

    If you want to debug only CURRENT feature, add this to 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"
        }
    }