Must-share information (formatted with Markdown):
- which versions are you using (SonarQube v8.1 and npm sonar-scanner v3.1.0)
- what are you trying to achieve - Get test report for an Angular project in Sonar
- what have you tried so far to achieve this:
- Added sonar-scanner v.3.1.0 to package.json
- Generate coverage report with angular ng test --code-coverage
- Verify locally that there is a lcov.info and index.html file, and they contain valid entries
- Execute npm run sonar from project folder
- Sonar does not include some folders.
Angular project src folder Structure:
src/app/ -> contains other folders and files
src/other/ -> contains other folders and files
src/util -> contains other folders and files
The Sonar instance does not include all files and folders under src/app, but only one folder. The ‘app’ directory has 20+ folders, which contain different angular files. 19 of them are ignored, despite lcov.info showing correct results.
There are a number of reasons why your coverage might not be respected, but my suspicion in your case is that the analyzer doesn’t know about the existence of your test files. Even if the tests are mentioned in the lcov.info file, the test files must also be found an indexed by our SonarJS Coverage sensor.
Since Angular likes to co-mingle test and source files together, it’s necessary for such projects to use exclusion/inclusion properties to properly differentiate each and make sure all the right files are found.
I actually created an example exactly to demonstrate this case in one of our public repos. Have a look at sonar-project.properties, particularly these properties:
What this is accomplishing is to tell the scanner the sources and tests are all in the same folder, and then to make sure the test files are not seen as regular source files but are seen as tests.
Hope this helps,
I noticed you replied here - but turns out I have a similar issue that has appears only since 6th March - raised it here Sonar Typescript Coverage Failing
Even with a minor change with your
sonar.coverage.exclusions example - still nothing, yet I am also including the tests through
One difference is my setup here is multi-module to support a mono-repo approach with Angular.
I’ve kind of the same configuration, as you’ve showed in the example, but the problem was elsewhere.
Long story short - due to PATH inconsistency, Jenkins could not assign the correct PATH to the appropriate Node version, and used something archaic.
Node 10.19 fixed it for me.
Great! Glad it’s sorted out.
A post was split to a new topic: Angular coverage with Jest