gpt4 book ai didi

reactjs - 将 ts-jest 与 create-react-app 一起使用

转载 作者:行者123 更新时间:2023-12-03 15:50:55 26 4
gpt4 key购买 nike

使用时 create-react-appreact-scripts-ts使用 TypeScript,使用 --coverage 运行测试flag 导致不正确的覆盖率报告。有没有办法集成 ts-jest 以便覆盖报告准确?

以下是我在 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
}
}
}
}

编辑:这是我收到的错误消息:
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.

最佳答案

您是否有任何理由使用 react-scripts-ts/ts-jest而不是常规的开箱即用的 Create React App?它在本地支持 TypeScript 已经有一段时间了。我建议这样做,因为与 CRA 的默认值作斗争通常是一个痛点。

关于reactjs - 将 ts-jest 与 create-react-app 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48791201/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com