Search code examples
jestjsgitlabgitlab-cicode-coverageplaywright

Change coverage combination method for Gitlab from different sources


In the project I mainly use Playwright to test and collect coverage. It's around 50 pages which are covered in this way. Now I added Jest to test some util functions which do not directly show up in the Frontend.

Now I am trying to combine the coverage for both playwright and Jest. My problem is, that jest only covers two or three files while playwright covers around 50. So the default behavior of GitLab to display the average between the two percentage values does not display the coverage accurately. E.g. Playwright has a Coverage of 80% over 50 files while Jest only covers 10% for one file atm. Coverage is now at 45% overall.

I tried to use the Regex in my gitlab.yml described on GitLab in both jobs, which allows me to display the coverage in the first place.

I also tried to move the final coverage collection to a new job where I use

npx cobertura-merge -o ./coverage/combined-coverage.xml package1=./coverage/cobertura-coverage.xml package2=./coverage/cobertura-jest-coverage.xml

to create a combined coverage report to use in the reporting system. But If I try to use the Regex in this job instead of the other two, I see no coverage value at all.

I would expect to get a coverage value that matches the actual files I covered so e.g. 80% in the playwright files and added to that the value for one file covered in jest and not the 50:50 split between playwright and jest.

Gitlab screenshot off coverage

It looks like this in my MR where I add Jest. As you can See, my overall coverage is dropping by 34.90% which is a bit misleading.


Solution

  • I solved this by adding a -p tag to my merge command which prints the result. Then I adapted the regex to match the value I wanted to present:

     coverage: '/Total line Coverage: \d+\.\d+/'