9

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 .

Ben Smith
  • 19,589
  • 6
  • 65
  • 93
lipp
  • 5,586
  • 1
  • 21
  • 32

1 Answers1

9

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

Jeff Sheets
  • 1,181
  • 12
  • 18