No coverage metric for React Native

I have React Native project, and SonarCloud shows 0% code coverage.
I’m using Jest, and I ran the following for produce LCOV and JUnit reports:

  • jest --ci --reporters=default --reporters=jest-junit
  • jest --coverage

I have junit.xml under my project root directory, and coverage/lcov.info.
My Sonar config is including just

sonar.javascript.lcov.reportPaths=coverage/lcov.info

because I saw that “sonar.junit.reportspath” is deprecated, but couldn’t find which setting should replace it.
I’m running Sonar manually and see the following output:

INFO: Sensor SonarJS Coverage [javascript]
INFO: Analysing [..../coverage/lcov.info]
WARN: Invalid character encountered in file ...../src/scenes/welcome/assets/images/logo_color.png at line 1 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.
WARN: Could not resolve 2 file paths in [......./coverage/lcov.info], first unresolved path: ......../config/jest-framework.js
INFO: Sensor SonarJS Coverage [javascript] (done) | time=28ms

Hi Vitaly,

Welcome to the community!

Indeed sonar.junit.reportPath (without the s) is deprecated but you can use sonar.junit.reportPaths instead.

Looking at the output you shared it’s weird to see that there are some png files encountered while analysing your lcov files… Could you share your whole sonar-project.properties files ?

Good point, thanks!

I started from empty one, now I have

  sonar.c.file.suffixes=-
 sonar.cpp.file.suffixes=-
 sonar.objc.file.suffixes=-
 sonar.javascript.lcov.reportPaths=coverage/lcov.info

Ok, it does looks correct indeed.
Is it a public project ? Could share a link to the repo and the sonarcloud page in a DM so that I can have a closer look ?

No, it’s private one.
I’ll send you detail via PM. Oops, there is no message option…

Any solution to this?

Sergio,
I don’t remember exactly fixes, but coverage works now, and here is my sonar config:

sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.junit.reportPaths=junit.xml
sonar.tests=src
sonar.test.inclusions=**/*.spec.ts,**/*.spec.tsx,**/*.spec.js,**/*.test.ts,**/*.test.tsx
sonar.testExecutionReportPaths=reports/test-report.xml
sonar.typescript.tslint.reportPaths=reports/tslint-report.json