Hello
Context
I’m setting up test coverage on a monorepo.
To do so, I’ve set up test coverage percentage with the coverage
property in all test-related jobs in gitlab-ci.yml.
I’ve also used the coverage_report
property to upload cobertura reports in order to show coverage visualization in the diff.
Example:
verify:serviceA:
extends:
- .verify
script:
- cd packages/serviceA
- yarn test --coverage --coverageReporters cobertura text
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: packages/serviceA/coverage/unit/cobertura-coverage.xml
As I am in a monorepo, there are multiple similar jobs like verify:serviceB
, verify:serviceC
etc.
Test jobs from service A are only triggered if changes were made on service A.
Problems
I can see the test coverage percentage in the MR but I’m encountering a few issues.
Test coverage is averaged among all apps
This is ok but I want to add a coverage check approval rule to ask for one more approver in MR if code coverage decreases.
Let’s say I have serviceA with 100% coverage and serviceB with 50% coverage.
If I make changes to both services, I’ll have 75% of coverage. But if in next pipeline I only make changes to serviceB, Gitlab will detect only a 50% coverage and will display a red -25% in the MR.
I’d rather test coverage to be compared to the same previous job because serviceA and serviceB are 2 different apps.
Are there any workarounds (without running every test job every time)?
Code coverage history is empty
There is no coverage history, I’m not sure if this is a bug or a misuse on my end but
coverage
property is properly set and test jobs are also run on master.
Manual jobs in MR pipelines
We have manual jobs in MR pipelines that trigger other pipelines from other repositories to launch a dynamic environment.
And, because from what I understand, cobertura reports are parsed only when the pipeline is complete (and manual jobs aren’t always run), coverage visualization isn’t working. Is there any workaround?
Other info
We are on premium Gitlab.com plan with gitlab-runner 12.7.1
Thank you for your help!