Please check that inclusion/exclusion patterns produce disjoint sets from main and test files. Sonarqube with Angular

Viewed 355

I have an angular project that is being scanned by Sonarqube through Jenkins. I get the code coverage but sonarqube won't show the number of unit tests (*.spec.ts files) we have written.

From sonarqube test script:

sonar-scanner \
    -Dsonar.sources=. \
    -Dsonar.tests=. \
    -Dsonar.exclusions=**/*.spec.ts \
    -Dsonar.tests.inclusions=**/*.spec.ts \
...

I have no access to the sonarqube ui since this is enterprise. Everything is being configured through scripts/config files in angular. Is there a way to see the number of angular unit tests on the sonarqube website after the scan is done?

P.S.: Originally I had -Dsonar.exclusions=node_modules, **/.spec.ts \ but this will throw an error on Jenkins saying **/.spec.ts is an unrecognized command.

1 Answers

There is a typo in your -Dsonar.tests.inclusions=**/*.spec.ts line.
It must be -Dsonar.test.inclusions=**/*.spec.ts. sonar.test.inclusions, not sonar.tests.inclusions
Had the same situation, found this after 20 minutes of seeing that frustrating error.

It is very strange that SonarQube allows this parameter to pass without any error or warning and most misleading thing is that there is more logic in -Dsonar.tests.inclusions then in -Dsonar.test.inclusions because of -Dsonar.tests.

Related