2

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

Matt B.
  • 397
  • 1
  • 4
  • 7
  • What is missing if you use MSBuild? Did you follow all the steps described in [this](https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Extension+for+VSTS-TFS) documentation page? – Jeroen Heier Jan 05 '18 at 19:11
  • i'm using Team City to run the builds with a powershell script calling the msbuild runner. I just can't seem to get the jest results with the jest coverage to combine with the .net vstests, I keep seeing a % of coverage, but 0 unit tests, or I will see unit tests, but then I select it and the page is blank. – Matt B. Jan 05 '18 at 21:27
  • But to answer your question, yes I am putting the steps in the correct order – Matt B. Jan 05 '18 at 21:47
  • 1
    @MattB.Did you manage to get it working for both C# and JavaScript? If yes, could you please share how you have done it? I am also trying to make the same, however it says could not resolve paths for the js files – Murali Murugesan Aug 16 '18 at 10:10

2 Answers2

1

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

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
  • Yes I have done that, and the files do appear, what's not happening is the jest coverage + the .trx + the coveragexml all coming together. – Matt B. Jan 08 '18 at 13:45
0

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
Boltyk
  • 317
  • 3
  • 10