Hi guys I have a express application and I'm playing around with gitlab to add Gitlab test coverage visualization
Here is my .gitlab-ci.yml
stages:
- test
- dockerize
- staging
- production
unit-tests:
stage: test
script:
- npm install
- npm run test
- npm run test-coverage
- cat coverage/cobertura-coverage.xml
- "echo 'Code coverage: 90.90'"
coverage: '/Code coverage: \d+\.\d+/'
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "master"'
- if: '$CI_COMMIT_BRANCH == "release-v1"'
artifacts:
reports:
cobertura: coverage/cobertura-coverage.xml
tags:
- demo
dockerize-application:
stage: dockerize
script:
- echo "dockerizing application"
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "master"'
- if: '$CI_COMMIT_BRANCH == "release-v1"'
tags:
- demo
deploy_to_staging:
stage: staging
script:
- echo "deploying to staging"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
tags:
- demo
deploy_to_production:
stage: staging
script:
- echo "deploying to production"
rules:
- if: '$CI_COMMIT_BRANCH == "release-v1"'
tags:
- demo
In my package json, here is the important part:
"scripts": {
"start": "node ./bin/www",
"debug": "nodemon ./bin/www",
"test": "npx nyc --reporter text mocha",
"test-coverage": "npx nyc --reporter cobertura mocha"
}
In the logs, I can see that the coverage file is uploaded.
Runtime platform arch=amd64 os=windows pid=19548 revision=775dd39d version=13.8.0
coverage/cobertura-coverage.xml: found 1 matching files and directories
Uploading artifacts as "cobertura" to coordinator... ok id=1097622443 responseStatus=201 Created token=6wcrN_d_
I did a lot of research and I still can't figure out why! I figured that was a feature flag turning this feature off by default but not any more:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43711
Here is the link to my project: I mainly created to experiment with gitlab ci/cd
Simply put, Cobertura is a reporting tool that calculates test coverage for a codebase – the percentage of branches/lines accessed by unit tests in a Java project.
1. Cobertura Code Coverage Report. Do nothing, just type the following Maven command to download and run the maven-cobertura-plugin automatically. Maven will generate the Cobertura code coverage report at ${project}/target/site/cobertura/index.
It's now working. The issue was that I needed to wait for the WHOLE pipeline to succeed before I could actually see the visualization.
Here is an issue open in Gitlab:
https://gitlab.com/gitlab-org/gitlab/-/issues/236248
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With