在 VS Code : Breakpoints Move 中调试 Jest 测试

标签 debugging visual-studio-code

在 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/

相关文章:

node.js - 在 vscode 中调试时如何将 NODE_PATH 设置为 $(pwd)

debugging - Safari JavaScript 控制台不执行 JS 或在某些页面上显示输出

ios - 尝试启动 “D’ 时无法在 “Name of app” s iPhone 上启动调试服务器”

xml - 在 visual studio 2010 中调试 xslt 文件

android - 在 Firefox 上调试 Android 应用程序

java - 如何执行OpenJDK调试包

ruby-on-rails - 如何让 RSpec 在 VSCode 中与调试器 IDE 一起工作

visual-studio-code - 你如何在 VSCode 中拆分终端?

python - 我如何让 Pylance 忽略 None 的可能性?

linux - 如何更改 Visual Studio 代码中的工作台字体?