In CI/CD processes, test coverage is critical for measuring the quality of our software projects. However, in large projects where tests run in parallel across different modules or even on different machines, multiple Cobertura coverage files may be generated. In such cases, correctly collecting and merging these coverage reports into a single report becomes essential. This is where comes in, merging all the Cobertura coverage files into one.
What is @yartasdev/cobertura-collect?
@yartasdev/cobertura-collect is an npm package that collects all Cobertura coverage files generated after running unit tests in a CI/CD pipeline and merges them into a single cobertura-coverage.xml file. This way, you can easily merge coverage reports from multiple modules into one file and present this combined report to CI/CD tools.
The package’s primary goals are:
- To locate multiple cobertura-coverage.xml files.
- To merge these files into one comprehensive coverage report.
- To provide this merged report to CI/CD tools.
How Does the Package Work?
The package scans a specific directory or directories for Cobertura reports and merges them into a single file. For example, after running parallel test processes, you can use this package to merge all the cobertura-coverage.xml files into one.
Install the Package or use without Install
npm install @yartasdev/cobertura-collect -g
and run command
@yartasdev/cobertura-collect --print -o coverage/cobertura.xml -t coverage/**/cobertura-coverage.xml
or without install
npx @yartasdev/cobertura-collect --print -o coverage/cobertura.xml -t coverage/**/cobertura-coverage.xml
Example CI/CD Configuration
Unit-Test:
stage: test
image: node:${NODE_LTS}-alpine
artifacts:
when: always
paths:
- coverage/
reports:
coverage_report:
coverage_format: cobertura
path: coverage/cobertura.xml
before_script:
- npm ci --cache .npm --prefer-offline --silent
script:
- npx nx run-many --target=test --configuration=ci --with-deps=false --projects=${PROJECTS} --parallel=6 --skip-nx-cache=false --verbose
after_script:
- npx @yartasdev/cobertura-collect --print -o coverage/cobertura.xml -t coverage/**/cobertura-coverage.xml
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
SOCIAL SHARE CARD GENERATOR