我正在尝试调试在Visual Studio Code中用es6编写的测试但是行编号完全错误:断点有效,我可以单步执行代码,但突出显示的行在错误的行上。
我在Visual Studio Code中看到的代码是es6源代码而不是es5 babel配置为输出。行编号似乎符合我想象的es5代码的样子。
这是我的Visual Studio代码配置,请注意我已将sourceMaps设置为true,并将outDir设置为null,如建议的in this question,但它仍然不起作用:
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Debug mocha",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "${workspaceRoot}\\node_modules\\mocha\\bin\\_mocha",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": [
"test/.setup.js",
"--reporter", "list",
"--compilers", "js:babel/register",
"--recursive", "./src/**/*.spec.js", "./src/**/*.integrationSpec.js", "./test/**/*.spec.js"
],
// Ensure use sourcemaps generated by babel
"sourceMaps": true,
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": "${workspaceRoot}",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
// Environment variables passed to the program.
"env": {
"NODE_PATH": "${workspaceRoot}\\src;${workspaceRoot}\\src\\framework\\core\\PageBuilder;${workspaceRoot}\\test\\testUtilities",
"NODE_ENV": "test"
},
"externalConsole": false,
"outDir": null
}
]
}
我使用的是Visual Studio Code 0.10.11版。 节点版本5.7.0 摩卡版本2.3.3
答案 0 :(得分:0)
以下“ launch.json”适用于摩卡咖啡和babel:
{
"type": "node",
"request": "launch",
"name": "Debug Mocha",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/mocha",
"runtimeArgs": [
"--require",
"babel-polyfill",
"--require",
"@babel/register",
"--recursive",
"${workspaceFolder}/tests"
],
"internalConsoleOptions": "openOnSessionStart"
}
要解决断点停在错误行的问题,请打开“ .babelrc”文件,并添加“ sourceMaps”和“ retainLines”,我的样子如下:
{
"presets": ["@babel/preset-env"],
"sourceMaps": "inline",
"retainLines": true,
}