How to generate code coverage for ASP.NET MVC (.Net Core 3.1) based project which has C#, JS and HTML codes?

Currently code coverage is showing only for C#. It’s not showing for JavaScript and HTML.

Need a help on code coverage to show per C#, JavaScript and HTML.

@Andrei_Epure: Any help on this topic

Hi,

Please don’t invoke people who haven’t volunteered themselves to help in your thread.

Additionally, more context on your build/analysis situation and what you’ve tried will really be required before anyone can be of much use to you.

 
Ann

2 Likes

Hi @ganncamp: We have implemented sonarcloud in our Azure DevOps build pipeline. We have followed this url https://sonarcloud.io/documentation/analysis/scan/sonarscanner-for-msbuild/ to implement build pipeline for Dotnet Core project.

Here is brief info about our code base

  • ASP.NET MVC Core
  • C#
  • AngularJS
  • JavaScript
  • HTML 5
  • CSS 3

Initially there were hurdle but got the help from this community and finally build pipeline has started working. Currently we are experiencing code coverage issues. We can see code coverage for C# but don’t see code coverage for JavaScript.

Can we get any help “How to setup code coverage for JavaScript”?

Much appreciated for any suggestions!

Hi @aarzoo2001

have you tried setting up the relevant javascript coverage paths property to pass with the scanner ?

Does you JS code analyzed with the same scanner run as your .NET code ?

Hi @mickaelcaro: Thanks for the reply. Here is the settings of test reports.

sonar.javascript.lcov.reportPaths=**/coverage/lcovonly/lcov.info sonar.cs.vstest.reportsPaths=**/*.trx

I have already verified, unit tests report files are generating.

Let me know what you want to see to do more troubleshoot.

Hi @aarzoo2001

Sorry i was mistaken at first, we do not support the merging of coverage files coming from multiple languages (such as your case)

My best solution for you would be to split analyses in 2 separates SonarCloud projects (One analysis analyzing the dotnet code with coverage for SC project 1, and the other one for js files with their coverage as well for SC project 2 for example) to ensure the best results.

HTH,
Mickaël

Hi @mickaelcaro - It’s ok, I can understand. Thanks for the reply and suggestion.

Look, here is the update on my end. Per your suggestion, I was able to convince my team and ready to have 2 projects (CSharp and JS).

We set it up the build pipeline (Azure DevOps) for JavaScript. Please find the screen shot of my Prepare Analysis For SonarCloud

I am unable to see the JavaScript Code Coverage, here is my sonar dashboard screen shot.

I have verified LCOV report generation and it’s generating. Here is the screen shot of the log.

Please let me know what to do next to show the code coverage on dashboard.

Regards,
Aarzoo

Hi @aarzoo2001

First, On the additional properties, sonar.host.url, sonar.organization, sonar.projectKey and sonar.login are not needed (they are populated within the extension with the configuration set above this field.

For the coverage path, please use any available variable in azure pipeline (like Agent.BuildDirectory, of System.DefaultWorkingDirectory) instead of putting double stars at the very beginning, that might help.

Mickaël

Hi @mickaelcaro - Thanks and appreciated for the reply.

We followed your suggestion. Please have a look and here is the screen shot of Prepare Analysis For SonarCloud

Here is the log file of Istanbul unit test coverage for your reference.
Istanbul-unit-test-coverage.txt (9.9 KB)

After this change, we still don’t see the code coverage on the sonar dashboard. Please have a look here.

Could you please suggest us further to fix this issue?

Regards,
Aarzoo

Hi @aarzoo2001

Can you please send me the log of the Run Code Analysis task, ideally in debug mode ? (either set sonar.verbose=true in the additional properties field of the prepapre analysis configuration , of set the system.debug=true pipeline variable.

Thanks !

Hi @mickaelcaro, Thanks and appreciated for the reply.

Please find the log of Run Code Analysis task.
Run-Code-Analysis-Task-Log.zip (563.3 KB)

Let us know your feedback.

Hi @aarzoo2001

After reading the logs, the coverage file is seek at this place :

D:\a\1\s\src\{project}\Tests\coverage\lcovonly\lcov.info

Which seems to be wrong ?
Can you try by putting this kind of value in the reportpath property ?

$(System.DefaultWorkingDirectory}/Tests/coverage/lcovonly/lcov.info

Mickaël

Hi @mickaelcaro - I fixed the path issue.

Please find the log file again for Run Code Analysis Task.
Run-Code-Analysis-Task-Log_1.zip (513.2 KB)

Issue still exist and unable to see JS Code Coverage. Let me know your update.

I think that the file path to coverage is still wrong. What is the latest setting you put for that in your pipeline ?

Hi @mickaelcaro: Thanks for the reply.

Please find attached the log file of Run Code Analysis Task.
Run-Code-Analysis-Task-Log_2.zip (527.9 KB)

I found one thing into this log, please find the screenshot. Can you provide any clue about this?

Hi @mickaelcaro - Is there any update from you? Any suggestion or hint to fix this issue.

I think the error is self explaning here : for some reason, the karma.conf.js file was not resolved propery while trying to parse the coverage file. Can you make sure that the file is propery located where it should be ?

Hi @mickaelcaro - This file is there at the original file location. This file is properly located.

Otherwise, why they need this file (karma.conf.js)? If we have already generated the lcov report and get sensed the folder and file exists, why it’s looking for this karma config file.

Could you please give us a bit more info on this?

There are probably some references inside the info while maybe ?

I saw also in the logs that those files seems to be picked up for analysis by our Scanner. Might be good to exclude them. WDYT ?

Hi @mickaelcaro - Thanks and appreciated for the reply.

I have already excluded folder (Tests) that has all our javascript unit test files (*.spec.js). Please have a look here in the screen shot.

Let us know your update.