Matt B.
Matt B.

Reputation: 437

SonarQube 6.7 .net and javascript in one project

My question is around the scenario where a .net web application has a UI project with javascript and JEST unit tests. Is it normal to have 1 sonarQube project that can accurately show the code coverage, VStests, and Jest Unit tests of both .cs and .js files?

I've tried with the msbuild runner and the sonar scanner and I just am not able to get it to work all under 1.

Thanks

Upvotes: 2

Views: 1169

Answers (2)

Boltyk
Boltyk

Reputation: 317

You can combine javascript and .Net unit tests and coverage in one SonarQube project. Coverage will be shown for both, but unit test count comes from javascript only (still don't know how to resolve it)

If you remove javascript unit test xml file line from additional SonarQube properties, you'll get unit test count for .Net without any other changes.

For .Net we use opencover to get .trx file and coverage xml:

"path/to/OpenCover.Console.exe" -register:user -target:"%MSTestExe%" -targetargs:"/resultsfile:Tests.trx /noisolation /testcontainer:%~dp0Tests\bin\%Configuration%\Tests.dll" -output:"%~dp0results.xml"

For javascript it's karma (jasmine) with karma-sonarqube-unit-reporter module to get lcov and xml files

And additional properties for SonarQube prepare analysis configuration step (integrated with MSBuild):

sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)\ProjectName\results.xml
sonar.cs.vstest.reportsPaths=$(Build.SourcesDirectory)\ProjectName\Tests.trx
sonar.genericcoverage.unitTestReportPaths=$(Build.SourcesDirectory)\ProjectName\tests\reports\ut_report.xml
sonar.javascript.lcov.reportPath=$(Build.SourcesDirectory)\ProjectName\tests\reports\coverage\lcov.info

Upvotes: 0

G. Ann - SonarSource Team
G. Ann - SonarSource Team

Reputation: 22794

In my experience, the analysis will pick up non-C# files if you include them in your project file, like so: <Content Include="src\**\*.js" />

For test coverage, I haven't tried it but it should work to define the JavaScript coverage-related properties on the Begin command line like so: /d:sonar.property.name=value

Upvotes: 1

Related Questions