【问题标题】:vscode jest breakpoint does not open in main editorvscode jest 断点未在主编辑器中打开
【发布时间】:2021-09-10 02:52:47
【问题描述】:

我正在运行一个 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-native 0.63.4 和节点 v16.4.0

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

【问题讨论】:

    标签: reactjs react-native visual-studio-code jestjs vscode-debugger


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2022-07-15
      • 2022-11-10
      • 2018-12-10
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      • 2022-01-14
      • 2021-08-07
      • 1970-01-01
      相关资源
      最近更新 更多