Issue
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 .
Solution
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
Answered By - Jeff Sheets