【问题标题】:Debugging Jest Tests in VS Code: Breakpoints Move在 VS Code 中调试 Jest 测试:断点移动
【发布时间】:2019-02-10 23:16:34
【问题描述】:

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 Code:1.27.0,无扩展;开玩笑:23.5.0;节点:8.10.0; Ubuntu Linux 16.04

【问题讨论】:

  • 你能添加一个最小的代码示例吗?
  • 好的,我会粘贴的。

标签: debugging visual-studio-code


【解决方案1】:

我自己找到了“解决方案”。 将 .babelrc 文件添加到您的根文件夹中,内容如下:

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

那么问题就没有了。

虽然我没有专门使用 Babel,但 VS Code 确实有点用。

【讨论】:

  • 找了两天...谢谢!!
【解决方案2】:

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

{
  "disableOptimisticBPs": true
}

这对我和several other people 有用。

【讨论】:

  • 我希望我能投票超过九千次。
  • 也许 vscode 应该重命名选项“disablePullingHairOut”并将true 设为默认值。
  • 这工作了一段时间,然后停止使用最近的 vscode 更新。真气。
  • 可以确认,此选项自 2020 年更新起不再有效
猜你喜欢
  • 2018-08-06
  • 1970-01-01
  • 2018-05-13
  • 2019-05-14
  • 1970-01-01
  • 2019-12-29
  • 2020-03-16
  • 1970-01-01
  • 2022-12-23
相关资源
最近更新 更多