I have a typescript project that goes through a Jenkins pipeline and does all the functional tests in parallel (after building the main container). At the end of the pipeline - we create code coverage check and then ship the result out to sonarqube.
here is my package.json:
"test": "npm run test:unit && npm run test:component && npm run test:functional",
"test:component": "mocha --reporter mocha-sonarqube-reporter --reporter-options output=tests/coverage/component/test-xcomponent.xml --recursive -r ts-node/register tests/component/*.ts",
"test:functional": "mocha --reporter mocha-sonarqube-reporter --reporter-options output=tests/coverage/functional/test-xfunctional.xml --recursive -r ts-node/register tests/functional/*.ts",
"test:unit": "mocha --reporter mocha-sonarqube-reporter --reporter-options output=tests/coverage/unit/test-xunit.xml --recursive -r ts-node/register tests/unit/*.ts",
"test:unit:nosq": "mocha --recursive -r ts-node/register tests/unit/*.ts",
"lint": "tslint -t verbose --project tsconfig.json -c tslint.json",
"cover": "nyc --report-dir tests/coverage/all npm run test",
"cover:unit": "nyc --report-dir tests/coverage/unit npm run test:unit",
"cover:functional": "nyc --report-dir tests/coverage/functional -x 'app/repositories' -x 'app/entities' -x 'app/utils' --no-clean npm run test:functional"
my sonar-project.properties is like the following:
sonar.exclusions=**/node_modules/**,**/*.spec.ts,app/entities/**,dependency-check-report/*,tests/coverage/**/*
sonar.tests=tests
sonar.test.inclusions=tests/**/*
sonar.ts.tslintconfigpath=tslint.json
sonar.typescript.lcov.reportPaths=tests/coverage/all/lcov.info
I have two problems with this setup:
I cannot seem to find a way to merge the different coverage files. I have checked the official istanbuljs/nyc GitHub and it states that it can combine via
nyc mergecommand however the output is .json and sonarqube requires xml. I am stuck with half my code coverage since I'm only shipping out one file out and not the combine file.I currently have code smell errors from the tests/coverage/all folder as it considered missing fonts from the generated coverage is being missing. I have excluded that folder in the
sonar-project.propertiesfile and I've included it in the .gitignore too but sonarqube is still reporting it as code small.