reactjs - 获取断点以使用 jest、Visual Studio 代码和自定义 typescript 转换器

标签 reactjs typescript react-native visual-studio-code jestjs

我无法使用 ts-jest 在 VSCode 中设置断点作为自定义预处理器。 如果我使用 debugger 语句,它会在正确的位置中断,并显示正确的源,因此正在加载和解析源映射。

在每个断点 VSCode 报告: 断点被忽略,因为未找到生成的代码(源映射问题?)

这是我的设置(相同的设置在 webstorm 中使用 debugger 语句和断点都可以正常工作)

启动.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Jest",
      "program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
      "args": [
        "--runInBand",
        "--no-cache"
      ],
      "cwd": "${workspaceRoot}",
      "console": "integratedTerminal",
      "sourceMaps": true,
    }
  ]
}

.tsconfig.json:

{
  "compilerOptions": {
    "jsx": "react",
    "allowSyntheticDefaultImports": true,
    "target": "es2015",
    "moduleResolution": "node",
    "inlineSourceMap": true
  },
  "exclude": [
    "node_modules"
  ]
}

package.json>开 Jest

"jest": {
  "preset": "react-native",
  "transform": {
    "^.+\\.js$": "<rootDir>/node_modules/babel-jest",
    ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
  },
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
  "mapCoverage": true,
  "moduleFileExtensions": [
    "ts",
    "tsx",
    "js",
    "json"
  ],
  "globals": {
    "__DEV__": true
  }
}

.babelrc

{
  "presets": [
    "react-native"
  ],
  "sourceMaps": "inline"
}

最佳答案

这似乎已在 ts-jest 的更高版本中得到修复,但我不太确定原因。断点应该与上述设置开箱即用的节点 8 一起工作。

有关详细信息,请参阅:https://github.com/kulshekhar/ts-jest/issues/212

关于reactjs - 获取断点以使用 jest、Visual Studio 代码和自定义 typescript 转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44040545/

相关文章:

javascript - 将 this.state 值访问到其他类 [React Native]

javascript - 动态调用静态方法

angular - typescript 参数类型不匹配不会抛出错误

ios - React Native ios 选择器始终打开

javascript - 如何根据 React Native 中的条件在不同组件之间导航

angular - 禁用表单时,响应式表单有效属性返回 false

javascript - 在 React Native 中重新渲染 - 问题

reactjs - 想要隐藏和显示不透明度的方法不起作用?

reactjs - 将 testcafe 与随机页面路径一起使用

javascript - 如何过滤 ReactJS 中的数据收集