首页 > 解决方案 > vscode jest 断点未在主编辑器中打开

问题描述

我正在运行一个 react-native 应用程序,当出于某种原因尝试调试 jest 测试时,我似乎无法让它真正停止在代码本身上。相反,vscode 会打开一个单独的编辑器,其中包含转换后的代码。例如:

在此处输入图像描述

运行上述内容:

在此处输入图像描述

在调试 react-native 应用程序本身时,一切正常。我相信的相关文件是:

babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
};

和开玩笑的配置package.json

"jest": {
  "preset": "react-native",
  "setupFiles": [
    "<rootDir>/jest.setup.js"
  ],
  "globals": {
    "__TEST__": true
  },
  "transform": {
    "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
  },
  "transformIgnorePatterns": [
    "node_modules/(?!react-native|native-base-shoutem-theme|@shoutem/animation|@shoutem/ui|tcomb-form-native|react-navigation|@react-native-community/async-storage|@codler/react-native-keyboard-aware-scroll-view)"
  ],
  "testPathIgnorePatterns": [
    "App-test.js",
    "ui.test.js"
  ]
}

和vscodelaunch.json

{
  "name": "vscode-jest-tests",
  "type": "node",
  "request": "launch",
  "args": ["--runInBand",],
  "cwd": "${workspaceFolder}",
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "disableOptimisticBPs": true,
  "program": "${workspaceFolder}/node_modules/jest/bin/jest",
},

使用我刚刚更新到最新的react-native0.63.4和节点。v16.4.0

我确信这在过去可以工作,但是在这个项目上没有工作一段时间,所以不确定是什么更新破坏了它(如果它是节点、vscode、react-native 等)。

标签: reactjsreact-nativevisual-studio-codejestjsvscode-debugger

解决方案


我有同样的问题。通过更改转换配置,我能够使我的设置正常工作:

  transform: {
    '^.+\\.[jt]sx?$': ['babel-jest', { configFile: require.resolve('./babel.config.js') }]
  },

推荐阅读