Gitlab 管道不会因 Junit 测试用例失败而中止

Gitlab Pipeline is not aborting on Junit test case failure

Gitlab版本:v14.1.1 即使单元测试中有失败的测试用例,Gitlab 管道也成功了。

Gitlab.yaml代码:

unit-test:
  stage: Test
  script:
    - npm run test
  needs:
    - lint
  artifacts:
    when: always
    paths:
      - coverage
    reports:
      junit:
        - junit.xml
      cobertura:
        - coverage/cobertura-coverage.xml
    expire_in: 4 days
  only:
    - test-case-testing
    - merge_requests

测试结果:

更新:package.json

中使用的测试命令
"test": "node ./node_modules/nyc/bin/nyc.js --reporter=cobertura --reporter=html node_modules/cucumber/bin/cucumber-js src/use-cases --parallel 5 --format=json --fail-fast --require \"src/use-cases/**/!(index).js\" | cucumber-junit > junit.xml",

当有任何失败的测试用例时,如何中止 Gitlab 管道?我阅读了 this 但无法弄清楚我应该做哪些具体更改?

脚本中的以下更改解决了失败问题。

  stage: Test
  script:
    - npm run test
    - test -f junit.xml && grep -L "<failure" junit.xml

这解决了问题。