如何在VS Code中调试夜视测试 [英] How to debug nightwatch tests in VS Code
问题描述
我正在尝试使用VS Code调试Nightwatch e2e测试.我使用打字稿编写测试.仅当我在js文件中放置一个断点时,它才能工作,之后将其转至ts文件,并且可以从那里调试它.如果将其放在测试的ts文件中-它将永远不会停止,并写为断点被忽略,因为未找到生成的代码".我的源文件使用ts编译器编译到/dist/dev/specs/e2e/nightwatch文件夹中/src.launch.json中的代码
I'm trying to debug nightwatch e2e tests using VS Code. I write my tests using typescript. It can work only when I put a breakpoint in js file, after that it goes to ts file and I can debug it from there. If I put it in ts file of my test - it will never stop and it is written ""Breakpoint ignored because generated code not found". My source files are compiled using ts compiler to folder /dist/dev/specs/e2e/nightwatch/src. Code from the 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 similar problem? Any help would be appreciated.
推荐答案
在必须调试服务器端node.js aps的情况下,通常可以帮助我的一件事是使用
One thing that usually helps me in cases when I have to debug server side node.js aps - is to use gulp-sourcemaps and there play around with generated source paths (check value of the "sources" property in your js.map files) by making them absolute and perfectly matching your ts files locations:
例如:
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));
});
尽管它有点破烂-它每次都对我有用,并且设置非常简单.
Although it is a bit hackish - it works for me every time and is quite simple to setup.
这篇关于如何在VS Code中调试夜视测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!