SonarQube TypeScript test integration

SonarQube version 8.4.1

  • what are you trying to achieve
    We are attempting to add our TypeScript & Karma based unit tests to the SonarQube analysis. Currently tests can be added & understood through the Generic Test Coverage report with the use of the npm package karma-sonarqube-reporter, but they cannot be understood as TypeScript files that also should be analyzed.

  • what have you tried so far to achieve this
    Followed the steps specified in https://sonarcloud.io/documentation/analysis/coverage/ to have the test files be included. Attempted to use the npm package suggested in that document to generate the generic coverage report, but could not get the package to successfully generate a valid report. Went with karma-sonarqube-reporter as an alternative and it generates a valid generic coverage report. This results in the tests being included & measured, but not understood as TypeScript files.

Test files are only specified via sonar.test.inclusions and nowhere else, which could be the source of the issue, but I could not find a proper config that would achieve the desired behavior

1 Like

Hi Sean, welcome to the SonarSource Community!

I configured a sample angular project to demonstrate how to approach this. Have a look, particularly at how I configured the source/test parameters in the sonar.properties file, as an indication of how you’ll probably have to approach it.

Note that you don’t need to use the Generic Test Coverage format; you can instead use a karma plugin like karma-coverage-istanbul-reporter to generate an lcov format report, which we support natively for JS/TS.