调试VS代码中的Jest测试:断点移动 [英] Debugging Jest Tests in VS Code: Breakpoints Move
问题描述
在VS Code中调试Jest测试时,我的断点会在启动调试器后立即移动几行。
When debugging Jest tests in VS Code my breakpoints move a few lines as soon as I start the debugger.
我使用官方推荐的配置,如上所述这里使用普通的JavaScript(不是Babel)。
I use the officially recommended configuration, as described here with plain JavaScript (not Babel).
我认为这与源地图有关。
在配置中设置sourceMaps:false
使我的断点不再移动,而是将真实源代码移动几行。
I think it has something to do with source maps.
Setting "sourceMaps": false
in the configuration makes my breakpoints not move anymore but shift the 'real' source code a few lines.
任何提示都非常感谢!
非常感谢您的帮助和最好的问候
Thanks a lot for your help and best regards
Arno
//二手软件
VS代码:1.27.0,无扩展名
VS Code: 1.27.0, no extensions
Jest:23.5.0
Jest: 23.5.0
节点:8.10.0
Ubuntu Linux 16.04
Ubuntu Linux 16.04
最小示例:
// hello_world.test.js
//hello_world.test.js
funTest = require('./hello_world.js')
const x = 15
test('this is a test', () => {
expect(funTest(5)).toBe(9)
})
// hello_world.js
// hello_world.js
const funTest = () => {
return 9
}
module.exports= funTest
现在,如果在 const x = 15
处设置断点,您将看到它被转移到 expect(funTest(5))。在调试会话期间toBe(9)
。
Now if you set a breakpoint at const x = 15
you will see that it is shifted to expect(funTest(5)).toBe(9)
during the debugging session.
推荐答案
我自己找到了'解决方案'。
使用以下内容将.babelrc文件添加到根文件夹中:
I found out the 'solution' myself. Add a .babelrc file into your root folder with the following content:
{
"sourceMap": "inline",
"retainLines": true
}
然后是问题已经消失。
即使我没有特别使用Babel,VS Code也有所帮助。
Even though I do not use Babel specifically, VS Code somewhat does.
这篇关于调试VS代码中的Jest测试:断点移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!