如何在VS Code中调试夜视测试

Kat*_*tia 6 debugging automated-tests typescript nightwatch.js visual-studio-code

我正在尝试使用VS Code调试Nightwatch e2e测试。我用打字稿写测试。仅当我在js文件中放置一个断点时,它才能工作,此后它会转到ts文件,并且可以从那里调试它。如果将其放在测试的ts文件中-它将永远不会停止,并被写为““断点被忽略,因为未找到生成的代码”。我的源文件使用ts编译器编译到文件夹/ dist / dev / specs / e2e / nightwatch / src。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"
Run Code Online (Sandbox Code Playgroud)

也许有人有类似的问题?任何帮助,将不胜感激。

小智 5

在我的情况下,以下工作就像魅力一样。

这是项目结构。 以下是我的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
                  }
                 ]
}
Run Code Online (Sandbox Code Playgroud)

以上代码是在Visual Studio代码最新版本1.21.1中调试Nightwatch js项目的最低要求。我正在使用node.js v6.11.2。因此调试协议是遗留的。

谢谢你堆栈溢出。


Ami*_*mid 1

当我必须调试服务器端 Node.js aps 时,通常对我有帮助的一件事是使用gulp-sourcemaps并使用生成的源路径(检查 js.map 文件中“sources”属性的值)通过使它们绝对且完美地匹配您的 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));
});
Run Code Online (Sandbox Code Playgroud)

虽然它有点hackish - 它每次都对我有用并且设置起来非常简单。