jestjs - 关于 create-react-app 中所有已提交文件的 Jest 覆盖率报告
问题描述
在我的 create-react-app 中为所有提交的文件生成 Jest 覆盖率报告时遇到困难。
最初,代码覆盖率按预期生成,但是我的环境发生了一些变化,现在只有自上次提交以来更改的文件显示覆盖率。
我看到有很多其他关于这个问题的帖子,但是我自己无法解决。
包.json:
{...
"devDependencies": {
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.6.3",
"react-test-renderer": "^17.0.1"
},
"jest": {
"testMatch": [ "**/tests/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ],
"coverageReporters": ["json","html","lcov", "text"]
}
...}
项目结构:
|
+--node_modules
+--src
|
+ __tests__
+ App.js
- package.json
运行命令npm test -- --coverage
会产生以下输出:
No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
解决方案
您处于监视模式,在对文件子集运行覆盖时存在一个已知问题。尝试使用--watchAll
,以便运行所有测试并生成覆盖率。
npm test -- --coverage --watchAll
为此,我喜欢在我的package.json
调用中制作一个特殊的 npm run-script coverage
。
推荐阅读
- python - Odoo TypeError:无法读取未定义的属性“显示”
- vue.js - Vue algolia 自动提示选择显示 [Object object]
- vba - 如何在 Power BI 中制作条件列
- javascript - 将数据属性添加到 select2 中的实际选择选项中
- javascript - 动态更新 Vue 路由参数
- python-3.x - 为什么不在 Python 中显示我的图像根目录?
- javascript - 关于 AWS Lambda RDS + dynamoDB 在同一个函数中查询的基本 JS 问题
- java - java - 如何在java中将字符串从字符串中的一个特定单词拆分为同一字符串中的另一个特定单词?
- python - print() IndentationError: python 语言
- currency - 欧洲央行对欧元的官方美元汇率