在 VS-Code 中调试 Jest 测试时,我的断点一启动调试器就会移动几行。
我用的是官方recommended configuration使用纯 JavaScript(不是 Babel)。
我认为这与源 map 有关。
设置 "sourceMaps": false
在配置中使我的断点不再移动,而是将“真实”源代码移动几行。
最小示例:
// 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
const funTest = () => {
return 9
}
module.exports= funTest
现在,如果您在
const x = 15
处设置断点你会看到它被转移到 expect(funTest(5)).toBe(9)
在调试 session 期间。二手软件
VS 代码:1.27.0,无扩展;开玩笑:23.5.0;节点:8.10.0; Ubuntu Linux 16.04
最佳答案
我自己找到了“解决方案”。
将 .babelrc 文件添加到您的根文件夹中,内容如下:
{
"sourceMap": "inline",
"retainLines": true
}
那么问题就迎刃而解了。
尽管我没有专门使用 Babel,但 VS Code 在某种程度上确实使用了 Babel。
关于在 VS Code : Breakpoints Move 中调试 Jest 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52191409/