Job fails because of console.error

I have Jest tests running in a Pipeline Job. I am using Jest in version 27.4.4.

The .gitlab-ci.yml has 2 jobs: prep and unit tests.

  stage: prep
    - node -v
    - npm -v
    - npm ci

unit tests:
  stage: test
    - 'npm run test'
  coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
    when: always
      - test/unit/coverage
      - test/unit/reporter
    expire_in: 1 day
    - schedules

The package.json has this script: "test": "jest --coverage"

The tests succeed but the job fails with exit code 1. When I run npm run test on my local machine it returns exit code 0. Running it with a local gitlab runner (14.9.1) the job succeeds as well. I expect the job to succeed as long as the tests succeed even if there are console.errors in the log.

I am using

I’ve mocked console.error to an empty function. Without having console.error in the log the job succeeds. I’ve tried it with a shared runner (14.9.0~beta.68.g1283960c) and a self hosted runner ( 13.4.0) with the same result (failing when there are console.errors).

Screenshot 2022-04-04 at 16.01.18