Gitlab Coverage Badge Shows "Unknown" - NodeJS with Jest

Viewed 108

Im having an issue where my gitlab coverage badge reports back as "unknown" for a NodeJS project Im working. Ive read through dozens of stackoverflow articles about this and tried all the suggested solutions to no avail, so I figured I would put the specifics of my setup in this post to see if anyone can pinpoint what might be causing the issue.

The job I have in my gitlab-ci.yml file is as follows:

 test_coverage:
  image: node:16
  stage: test_coverage
  before_script:
    - echo "This skips any predefined before scripts to ensure clean environments"
  tags:
    - Nexus
  script:
    - npm run test:ci
  coverage: /All\sfiles.*?\s+(\d+.\d+)/
  artifacts:
    when: always
    reports:
        junit:
            - ./junit.xml
        cobertura: coverage/cobertura-coverage.xml
  dependencies:
    - install
  except:
    - tags

The script npm run test:ci in my package.json files is as follows:

"test:ci": "CI=true NODE_ENV=test ENVIRONMENT=CI_CD NODE_OPTIONS=--experimental-vm-modules jest --coverage --collectCoverage --coverageDirectory=\"./coverage\" --ci --reporter=html --reporter=text --reporter=cobertura --reporters=default --reporters=jest-junit --watchAll=false"

I've got the following regex in the test coverage reporting settings section of gitlab

/All\sfiles.*?\s+(\d+.\d+)/

I have the badge link and URL set up as well in gitlab.

When I run my npm run test:ci script locally, I get a lovely coverage report returned. When my job runs in the gitlab pipeline, my coverage report has 0 for every file. It tells me all my tests ran and passed. It tells me that my junit and cobertura artifacts were successfully completed, and that the job succeeded.

I have a strong feeling that if I were seeing actual coverage numbers in the gitlab job logs like I see when I run the script locally, the badge would work. But I have no ideas why I'm getting all 0s reported. Can anyone see what Im doing wrong based on the info provided here?

0 Answers
Related