Jest在单元测试未通过时返回非零退出代码
但是当我将输出输出时,退出代码被抑制了
如何使基于linux环境变量${PIPESTATUS[0]}的作业失败?
我验证了PIPESTATUS[0]具有非零值
我尝试退出${PIPESTATUS[0]},但不起作用
我尝试了if语句,但可能没有正确的语法
- name: Install & test
id: unit_coverage_status
run: |
npm ci
npm run test-coverage | tee ./unit-coverage.txt
echo "Test coverage exit code: ${PIPESTATUS[0]}"
if ${PIPESTATUS[0]} == 0;
then
echo "Unit tests passed"
else
echo "Unit tests failed"
exit 1
fi
生成txt后,我将使用下面的步骤将结果添加到PR 中
- name: Jest integration coverage comment
uses: MishaKav/jest-coverage-comment@main
with:
coverage-path: ./int-coverage.txt
title: Integration Test Coverage
通过在命令中添加&& exit ${PIPESTATUS[0]}
,我能够捕获测试失败。
- name: Install & test
id: unit_coverage_status
run: |
npm ci
npm run test-coverage | tee ./unit-coverage.txt && exit ${PIPESTATUS[0]}
只有在测试通过时才会生成覆盖率注释。如果测试失败,我更关心的是显示它,而不是显示它的覆盖范围