Code Coverage Percentage for Angular project

Hi everybody, I can not see code coverage percentage for my project (Climb.web project it’s an angular project) in sonarCloud , I did some things like install “sonar-scanner”: “^3.1.0” and added on my package.json file, install “tslint-sonarts”: “^1.9.0” and added in the same file too, I created the “sonar-project.properties” file in the root path of my project with the follow configuration:

sonar.host.url=https://sonarcloud.io/
sonar.login=xxxxxxxxxxxx
sonar.organization=apmwnagsvswavvejryuocquyxqmqmtgyubfskdwlmevddbbtqqsmuzwvhliikwlmndtrfdkxklopvwsmtgzdaibixhhttksfeyn
sonar.projectKey=Climb.Web
sonar.projectName=Climb.Web
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=/node_modules/
sonar.tests=src
sonar.test.inclusions=**/*.spec.ts
sonar.typescript.lcov.reportPaths=coverage/lcov.info

but finally I can not see code coverage on my project, if you can give me some help I appreciate that

I dont know if I have to configurate something in my Karma.conf.js or in other file, I don’t know if the “sonar-project.properties”" file configuration is right (for example I login sonarcloud with my github credentials, so is it those credentials that I should use in that “sonar-project.properties” file? ).

so I appreciate any help or session

Hi @boterito3, welcome to the SonarSource Community!

Have a look here, I have an example project created for this purpose. You’ll see the key is to exclude the test files from being considered as source, then making sure they are included as tests.

1 Like

Hi Jeff , thank you so much for response my question, your project help me to configure my karma.conf.js file and I can create in my local enviroment a Code Coverage Report as you can see in this Image:

but I don know how to send that report to sonacloud yet, how to call sonnar scanner from CLI to send that report, I have a build in Azure for my project and that build is telling me that can not found any coverage file to be uploaded, so I think that coverage report is not be generating by any reason.

in your project I checked the build.sh file and there I see you run the test and after that you
call sonar scanner:
sonar-scanner -Dsonar.host.url=$SQ_URL -Dsonar.login=$SQ_TOKEN
I put my URL and my token but CLI not recognized the command.

if you can help me with any tip to do that, thank you

Hi @boterito3,

In my example repo, the file src/karma.conf.js includes configuration to generate the coverage report using the karma-coverage-istanbul-reporter plugin.

How you send the report to SonarCloud is shown in the sonar-project.properties file in the property sonar.javascript.lcov.reportPaths which is set to the output from the coverage report generated by karma.