如何在VS Code

时间:2017-05-04 13:34:03

标签: debugging typescript automated-tests visual-studio-code nightwatch.js

我正在尝试使用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"

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

4 个答案:

答案 0 :(得分:4)

在我的案例中,以下工作就像魅力一样。

Here is the project structure. 以下是我的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
                  }
                 ]
}

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

谢谢Stack Overflow。

答案 1 :(得分:1)

在我必须调试服务器端node.js aps的情况下,通常可以帮助我的一件事是使用gulp-sourcemaps并使用生成的源路径(检查"来源&#的值) 34; 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));
});

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

答案 2 :(得分:1)

如果您不需要打字稿部分(基于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"
        ]
    }
]

}

答案 3 :(得分:0)

我用那个:

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