I am trying to get code coverage working on several repos we have on GitLab. We use JUnit to generate unit tests and we can successfully generate the unit test report in the merge request. That coverage percentage does not populate the code coverage badge on the repo page, nor does it populate the Code Coverage Statistics in the Repository Analytics page for the repository.
This is the relevant part of the gitlab yml file:
.npm-test:
extends: [.npm-image, .npm-cache-pull]
dependencies: [install]
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
script:
- npm run test-ci
artifacts:
when: always
paths:
- junit.xml
reports:
junit:
- junit.xml
We are able to generate the junit.xml file successfully with both Jasmine/Karma and Jest for unit tests. For 3 out of 20 repositories we have, the code coverage badge and analytics are populated correctly with just the junit.xml file. For the rest, the badge and analytics are unknown and empty. I have several questions.
- Is Cobertura required to populate the code coverage badge and the code coverage statistics in the analysis page?
- If Cobertura is required, why do some of the repos correctly post the statistics?
- Does running Cypress in another step in the pipeline affect whether the statistics are reported correctly?
- Is there a gitlab setting in the individual repos that affects the code coverage generation?
I have scoured the gitlab documentation and have not been able to reconcile these discrepancies.
We are using the enterprise version of gitlab.
Thanks so much in advance!