For those who will have the same problem here is the solution I found:
sonarCloud accepts type: xml code coverage file, with the tool cobertura.
Like code-coverage.xml output.
I had to use the frameworks from my first message, defined in my package.json
1. So I use the following tasks on my scan pipeline:
- script: |
npx ng test --code-coverage --progress --karma-config src/karma-ci.conf.js --prod
displayName: Generate unit tests and report coverage
This task can be replaced by this one below.
- task: Npm@1
inputs:
command: custom
customCommand: run test:ci
displayName: Launch unit tests
But you will need to define in your package.json the script that can call the Npm@1 command custom run test:ci. By adding this to the script:
"scripts": {
"test:ci": "ng test --watch=false --karma-config src/karma-ci.conf.js",
},
2. And the other tasks of my pipline for publish unit tests and run analysis, and publish quality gate.
As you will see, you can either use SonarQube generic format for test coverage or the LCOV format supported by the JavaScript/TypeScript analyzer, which is quite common in the JavaScript community. For the latter, it’s not really my place to tell you which test framework you should use, but any framework that generates a .lcov file will do, e.g. Jest developed by Facebook seems to be pretty popular.
In any case, in order to import your code coverage report in SonarQube, your pipeline will need to run your unit tests and generate the coverage report before running an analysis as the scanner won’t do it for you. Furthermore, you will need to tell the scanner where to find the coverage report file by setting the appropriate property, e.g. sonar.javascript.lcov.reportPaths for .lcov files.