如何在GitHub动作中检查测试覆盖率百分比
我有一个已发布到Github的React项目,并试图设置GitHub动作。
我想添加一个步骤,以检查单位测试覆盖范围是否通过65%(必须通过它成功完成CI/CD过程)。
这是我尝试的:
build:
name: Test
steps:
- name: Coverage
run: npm run jest-coverage
我需要帮助以下项目:
- 如何检查覆盖率百分比是否通过65%?
- 如果覆盖范围低于65%,则如何使过程失败?
- 每当有新的提交推动时,我如何才能重新运行它?
I have a react project published to GitHub, and trying to set up GitHub Actions.
I want to add one step to check if the unit test coverage passes 65% (have to pass it to go through CI/CD process successfully).
This is what I've tried:
build:
name: Test
steps:
- name: Coverage
run: npm run jest-coverage
I need help on following items:
- How can I check if the coverage percentage passes 65%?
- How to make the process fail if the coverage is lower than 65%?
- How can I make it rerun it whenever there's a new commit pushed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的NPM脚本
开玩笑
在启用的覆盖范围内运行开玩笑,可以使用Jest Configuration coveragageThreshreshold 。
将其添加到您的
jest.config.js
:至于在推新代码时重新运行工作,您想在
push> push
上触发工作流,例如:关于您如何使用分支和拉请请求,
push
也可以用pull_request
替换。Assuming that your npm script
jest-coverage
runs jest with coverage enabledRequiring 65% test coverage can be achieved with the jest configuration coverageThreshold.
Add this to your
jest.config.js
:As for re-running your job when new code is pushed, you want to trigger your workflow on
push
, like so:Depending on how you're working with branches and pull requests, the
push
could also be replaced withpull_request
.