How to debug Nightwatch tests in VS Code

I am trying to debug e2e nightwatch tests using VS Code. I write my tests using typescript. It can only work when I put a breakpoint in the js file, after which it goes into the ts file, and I can debug it from there. If I put it in the ts file of my test, it will never stop and it will be written "Breakpoint is ignored because the generated code was not found." My source files were compiled using the ts compiler to the / dist / dev / specs / e 2e / nightwatch / src folder. Code from launch.json

        "name": "Launch e2e Tests on chrome",
        "type": "node",
        "console": "integratedTerminal",
        "program": "${workspaceRoot}/dist/dev/specs/e2e/nightwatch/nightwatch.js",
        "stopOnEntry": false,.
        "args": ["-env default,-f DatabaseChecks.js"],
        "cwd": "${workspaceRoot}",
        "runtimeExecutable": null,.
        "runtimeArgs": ["--nolazy"],
        "env": {
            "NODE_ENV": "development"
        },
        "sourceMaps": true,
        "outFiles": ["${workspaceRoot}/dist/dev/specs/e2e/nightwatch/src"],
        "request": "launch"

Maybe someone had a similar problem? Any help would be greatly appreciated.

+4
4

, , node.js aps - gulp-sourcemaps ( "sources" js.map), ts :

:

gulp.task('build', () => 
{
    var tsProject = ts.createProject('tsconfig.json', {
        typescript: require('typescript')
    });

    var tsResult = tsProject.src()
        .pipe(sourcemaps.init())   
        .pipe(tsProject()); 

        //Write compiled js
    return tsResult.js.pipe(sourcemaps.write(
            ".", 
            { 
                includeContent: false, 
                mapSources: function(sourcePath) 
                {
                    //Play around here - converting your relative paths to absolute ones that match location of ts file perfectly 
                    return sourcePath.replace('../../../', __dirname + '/');
                } 
            })).pipe(gulp.dest(TEMP_TARGET_FOLDER));
});

- .

+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": "Nightwatch",
                      "program": "${workspaceRoot}/node_modules/nightwatch/bin/runner.js",
                      "stopOnEntry": false,
                      "args": [
                                 "--test",
                                 "tests/functionality_e2e_test.js"
                              ],           
                       "runtimeExecutable": null,
                       "sourceMaps": false
                  },
                  {
                       "type": "node",
                       "request": "attach",
                       "name": "Attach to Process",
                       "port": 5858
                  }
                 ]
}

Nightwatch js 1.21.1. node.js v6.11.2. .

, .

+2

You can use this configuration if you do not need the Typescript part (based on WebStorm ):

{
"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceRoot}/node_modules/nightwatch/bin/runner.js",
        "args": [
          "--config",
          "test/e2e/nightwatch.conf.js"
        ]
    }
]

}

+1
source

I use this one:

{
    "type": "node",
    "request": "launch",
    "name": "Nightwatch 2",
    "port": 9229,
    "program": "${workspaceRoot}/node_modules/nightwatch/bin/nightwatch",
    "stopOnEntry": false,
    "args": [
        "--env",
        "localchrome"
    ],
    "cwd": "${workspaceRoot}",
    "sourceMaps": false,
    "env": {
        "ENV": "s11",
        "TAGS": "@WIP"
    },
    "runtimeArgs": [
        "--inspect"
    ]
}
0
source

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


All Articles