Jac*_*lan 6 mocha.js ecmascript-6 babeljs visual-studio-code
我试图在Visual Studio Code中调试用es6编写的测试,但是行编号都是错误的:断点有效,我可以单步执行代码,但突出显示的行在错误的行上.
我在Visual Studio Code中看到的代码是es6源代码而不是es5 babel配置为输出.行号似乎与我想象的es5代码看起来一致.
这是我的Visual Studio代码配置,请注意我已按照此问题中的建议将sourceMaps设置为true,将outDir设置为null,但它仍然无效:
{
"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
}
]
}
Run Code Online (Sandbox Code Playgroud)
我使用的是Visual Studio Code 0.10.11版.节点版本5.7.0 Mocha版本2.3.3
以下“launch.json”适用于我的 mocha 和 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"
}
Run Code Online (Sandbox Code Playgroud)
要解决断点停在错误行的问题,请打开“.babelrc”文件并添加“sourceMaps”和“retainLines”,我的如下所示:
{
"presets": ["@babel/preset-env"],
"sourceMaps": "inline",
"retainLines": true,
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
404 次 |
| 最近记录: |