[英]Using ts-jest with create-react-app
When using create-react-app
with react-scripts-ts
to use TypeScript, running the tests with the --coverage
flag leads to incorrect coverage reports.当使用
create-react-app
和react-scripts-ts
来使用 TypeScript 时,使用--coverage
标志运行测试会导致不正确的覆盖率报告。 Is there any way to integrate ts-jest so that the coverage reports will be accurate?有没有办法集成 ts-jest 以便覆盖报告准确?
Below is my jest configuration in package.json
:以下是我在
package.json
开玩笑配置:
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"mapCoverage": true,
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
}
}
Edit: This is the error message I am getting:编辑:这是我收到的错误消息:
Out of the box, Create React App only supports overriding these Jest options:
• collectCoverageFrom
• coverageReporters
• coverageThreshold
• snapshotSerializers.
These options in your package.json Jest configuration are not currently supported by Create React App:
• transform
• testRegex
• moduleFileExtensions
• mapCoverage
If you wish to override other Jest options, you need to eject from the default setup. You can do so by running npm run eject but remember that this is a one-way operation. You may also file an issue with Create React App to discuss supporting more options out of the box.
Is there any reason you are using react-scripts-ts
/ ts-jest
instead of regular out-of-the-box Create React App?您是否有任何理由使用
react-scripts-ts
/ ts-jest
而不是常规的开箱即用的 Create React App? It has been supporting TypeScript natively for a while now.它在本地支持 TypeScript 已经有一段时间了。 I'd suggest doing that, as fighting against in the defaults of CRA is generally a pain point.
我建议这样做,因为与 CRA 的默认值作斗争通常是一个痛点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.