I'd like to use Gitlab CI for tracking / embedding the coverage analysis in merge requests. The gitlab-ci.yml artifacts:reports:junit
config option seems to be suitable for this task. However, this requires the coverage
output to be in junit.xml format.
I don't find a proper setup for outputting the coverage this format. Neither can I find a tool to convert from lcov/json/clover to junit.xml .
To get Jest up & running, install it as a dev dependency in your project. For ease of use, also in your CI/CD pipelines, I recommend to add script entries for running Jest with and without collecting coverage statistics in your package.
It can be done with the jest-junit reporter plugin. https://github.com/jest-community/jest-junit
yarn add --dev jest-junit
Then execute this locally to see if it is working
yarn test --colors --coverage --reporters=default --reporters=jest-junit
And you'll see a junit.xml file in root.
Configure your .gitlab-ci.yml like this to then see the output in Gitlab:
test:
stage: test
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
artifacts:
reports:
junit: junit.xml
script:
- yarn test --colors --coverage --reporters=default --reporters=jest-junit
Oh and add the coverage/ folder and junit.xml to .gitignore so they aren't added to the git repo.
This all seems to work ok in a Create React App project too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With