How to debug a CucumberJS script using Visual Studio Code

I am building cucumberjs tests using Visual Studio code. I can run tests using npm from the command line, and I can run them from VS code using the launch configuration.

However, I cannot debug the test from Visual Studio code. This is on Windows 7 with VSCode 1.12.1

Basic file structure:

.
+-- .vscode
|   +-- launch.json
+-- features
|   +-- step_definitions
|   |   +-- sampleSteps.js
|   +-- support
|   |   +-- customWorld.js
|   +-- sampletest.feature
+-- node_modules
|   +-- .bin
|   |   +-- cucumberjs
+-- package.json
+-- README.md

Inside package.json, I have the following:

  "scripts": {
    "test": "./node_modules/.bin/cucumberjs"
  },

At the command prompt, I can successfully execute npm testor npm run-script test. I have launch.json configuration as follows:

{
    // 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"
            ]
        }
    ]
}

When I run Debugger from VS Code, it just runs the test, giving me the results, but does not follow breakpoints.

, , launch.json - . launch.json, , , ( cucumberjs).

+4
1

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)

+2

Source: https://habr.com/ru/post/1676779/


All Articles