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 “” file in the root path of my project with the follow configuration:

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 “”" file configuration is right (for example I login sonarcloud with my github credentials, so is it those credentials that I should use in that “” 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.


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 file and there I see you run the test and after that you
call sonar scanner:
sonar-scanner$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 file in the property sonar.javascript.lcov.reportPaths which is set to the output from the coverage report generated by karma.

1 Like

Jeff, again than you for your help and your time, I can advance a llitle bit more, now I can generate my file in the “coverage” folder, I got this adjusting some things in my Karma.conf.js, now the problem is trying to send that report to sonarcloud, I followed yours, and the most important thing is the propertie: “sonar.javascript.lcov.reportPaths” this is the path where is located my “” file Right?

but when I run the build of my project I am getting this error:

Sorry but I need your help again :s

In the configuration of your Prepare Analysis task, you’ll want to change the setting from using the scanner for MS Build to using the “standalone” scanner. The default MS Build setting should only be used for a Microsoft .NET solution. Since you have what appears to be pure JS/TS the standalone scanner should be run instead.

1 Like

Jeff, thank you so much for your help, I really appreciated that, I learned so much doing this, and I want to show you that I can visualize the coverage on my sonarcloud.

1 Like