调试VS代码中的Jest测试:断点移动

问题描述 投票:6回答:2

在VS-Code中调试Jest测试时,一旦启动调试器,我的断点就会移动几行。

我使用正式的recommended configuration和普通的JavaScript(不是Babel)。

我认为这与源地图有关。在配置中设置"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)

二手软件VS代码:1.27.0,无扩展名;开玩笑:23.5.0;节点:8.10.0; Ubuntu Linux 16.04

javascript debugging visual-studio-code jestjs
2个回答
17
投票

我自己发现了'解决方案'。使用以下内容将.babelrc文件添加到根文件夹中:

{
  "sourceMap": "inline",
  "retainLines": true
}

然后问题就消失了。

即使我没有专门使用Babel,VS Code也有所帮助。


3
投票

将以下内容添加到vscode-jest-tests中的launch.json配置中:

{
  "disableOptimisticBPs": true
}

这对我和several other people有用。

© www.soinside.com 2019 - 2024. All rights reserved.