如何在 VS Code 中调试守夜人测试
How to debug nightwatch tests in VS Code
我正在尝试使用 VS Code 调试 nightwatch e2e 测试。我使用打字稿编写测试。只有当我在 js 文件中放置一个断点时它才能工作,之后它转到 ts 文件并且我可以从那里调试它。如果我把它放在我测试的 ts 文件中——它永远不会停止,它被写为““Breakpoint ignored because generated code not found”。我的源文件是使用 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"
也许有人遇到过类似的问题?任何帮助,将不胜感激。
在我必须调试服务器端 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));
});
虽然它有点老套 - 它每次都对我有用,而且设置起来非常简单。
如果不需要 Typescript 部分,可以使用此配置(基于 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"
]
}
]
}
我用那个:
{
"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"
]
}
在我的案例中,以下内容非常有效。
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。
我正在尝试使用 VS Code 调试 nightwatch e2e 测试。我使用打字稿编写测试。只有当我在 js 文件中放置一个断点时它才能工作,之后它转到 ts 文件并且我可以从那里调试它。如果我把它放在我测试的 ts 文件中——它永远不会停止,它被写为““Breakpoint ignored because generated code not found”。我的源文件是使用 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"
也许有人遇到过类似的问题?任何帮助,将不胜感激。
在我必须调试服务器端 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));
});
虽然它有点老套 - 它每次都对我有用,而且设置起来非常简单。
如果不需要 Typescript 部分,可以使用此配置(基于 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"
]
}
]
}
我用那个:
{
"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"
]
}
在我的案例中,以下内容非常有效。
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。