Code Coverage not reflecting in Sonar Cloud

We have a React app created using Create React App and have configured it according to sonar cloud documentation but code coverage is still not getting reported. The unit test coverage is being displayed on developers local systems and we are using the jest-sonar-reporter to properly format test output. We are using Github and Github Actions for CI platform and that is all configured to run the unit tests and then the sonar scan.

Please see our repo for project and sonar configuration and CI workflow

Hello Jason!

And welcome to the community!

First I see that you are using jest-sonar-reporter, this is third party module that is not needed. The expect format of coverage files is lcov which Jest is able to generate by itself. So you just need to make sure lcov is part of your coverageReporters Jest setting.

Then you should make sure that you have in your sonar-project.properties the sonar.javascript.lcov.reportPaths setting that point to your coverage report. You can also specify in Jest where the coverage report is generated with the coverageDirectory setting.

So as long as your lcov file is correctly generated and available at the place specified in the sonar.javascript.lcov.reportPaths settings it should work fine.