Code coverage not shown in the UI for Javascript application

Hello,

I try to analyse a React Native project with Sonarcloud.
My code is on a gitlab.com repository

The analysis works well but I do not have any coverage reports shown in the UI as you can see here:

Here is my sonar-project.properties file:

sonar.projectKey=groupemutuel.io_gmapp
sonar.organization=groupemutuelio

sonar.exclusions=**/*.java

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

sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

And the definition of my job in my CI:

sonar:
  image:
    name: sonarsource/sonar-scanner-cli:4.7
    entrypoint: [""]
  stage: quality
  needs:
    - job: Test
      artifacts: true
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - sonar-scanner
  only:
    refs: *build_and_publish

The job that this one depends is “Test” and it produces a coverage/lcov.info file that is passed to the Sonar job as an artifact

You can find here the content of the artifact passed to the Sonar Job.
artifacts.zip (182.1 KB)

When I looked at the logs, I did saw a warning but I don’t know if that’s the root cause…

INFO: Analysing [/builds/GDbogi_A/3/groupemutuel.io/plateforme-front-office/assures/gmapp/coverage/lcov.info]
WARN: Could not resolve 50 file paths in [/builds/GDbogi_A/3/groupemutuel.io/plateforme-front-office/assures/gmapp/coverage/lcov.info]
WARN: First unresolved path: /builds/GDbogi_A/1/groupemutuel.io/plateforme-front-office/assures/gmapp/src/modules/@docs/producer/store/actions.js (Run in DEBUG mode to get full list of unresolved paths)
INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=17ms

When I look at my repository I can indeed find the expected file…

Thanks in advance for your help!

Grég

Hey there.

The issue comes from the fact that absolute paths are used in the coverage report that don’t match the file paths in the environment the scanner is running.

  • You can try and see if your coverage reporter supports paths relative to the root of your project
  • Some users find it possible to post-process the coverage report using sed to fix the paths
  • You could run your tests in the same environment as you run analysis

Hello @Colin

I am sorry, until I find a way to connect again on my other account and change my primary email (as described here: How to change my primary email in my Sonar Community profile?), I’ll have to answer with another account :wink:

Anyway, thanks for your reply.
I tried the third option that you proposed → run the analysis on the same environment as I execute the tests

Unfortunately, I still have the same warning with path that are not found…

INFO: Analysing [/builds/GDbogi_A/0/groupemutuel.io/plateforme-front-office/assures/gmapp/coverage/lcov.info]
WARN: Could not resolve 1 file paths in [/builds/GDbogi_A/0/groupemutuel.io/plateforme-front-office/assures/gmapp/coverage/lcov.info]
WARN: First unresolved path: /builds/GDbogi_A/0/groupemutuel.io/plateforme-front-office/assures/gmapp/src/modules/@tech/pdf/fixtures.js (Run in DEBUG mode to get full list of unresolved paths)
INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=27ms

And what is more wired it is that now the path seems the same for the lcov.info file and the file Sonar tries to read (/builds/GDbogi_A/0/groupemutuel.io/plateforme-front-office/assures/gmapp)

Here is my gitlab-ci’s job up to date with the modification:

Test & Quality:
  image: $NODE_IMAGE
  stage: build
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  script:
    - |
      # printing the job status
      echo "**********************************************"
      echo "*************** yarn install *****************"
      echo "**********************************************"
    - yarn --frozen-lockfile --network-timeout 300000
    - |
      # printing the job status
      echo "---------- yarn install successfull ----------"
      echo "**********************************************"
      echo "*************** Quality tasks ****************"
      echo "**********************************************"
    - yarn run lint && yarn test --ci
    - yarn global add sonarqube-scanner
    - yarn sonar
    - |
      # printing the job status
      echo "--------- Quality tasks successfull ----------"
  only:
    refs: *build_and_publish

Thanks for your help!

Let me suggest you bump up to DEBUG level logging (sonar.verbose=true) in your current configuration and upload the logs. A recent copy of the coverage report (as you provided earlier) would also be useful to compare.

Hi @Colin,

Yes, here is a link to download the requested information

Thanks for your feedback.

@Colin any news on that topic ?

Hi @Colin

Any news on that topic ?
Not sure that you can download the files anymore…

Let me know if you need a new link

Best

Hello @Colin

Did you forget this post ?

Thanks for your help…

Hello,

I am sorry to open a new ticket but the one that I opened the 15th of March didn’t get any answer… I have been in touch with @Colin that asked my some question that I did answer but never heard him back.

Could anyone help me with that topic?

Thanks in advance for your help!

Grég

Hi Greg,

I’ve consolidated your posts.

I’ve just clicked the link to see the logs Colin requested & I was asked to accept a ToS to get to them. I suspect that’s where he stopped. It’s certainly where I stopped.

Please copy/paste your logs into this thread & code-format them.

 
Thx,
Ann

Hello @ganncamp and @Colin my bad…

I had to use WeTransfert because my log’s file was too big…
I just gave a new try today and here are the logs for the Sonar part.
As @Colin asked, you’ll find in the attachment the coverage folder’s content in the archive named artifacts.zip

Thanks in advance for your help :slight_smile:

Best,

Grég

raw.txt (3.7 MB)
artifacts.zip (182.7 KB)

Hi,

It’s a bit tough to read the logs at DEBUG level, so you might have overlooked this:

11:51:02.458 WARN: Could not resolve 50 file paths in [/builds/GDbogi_A/0/groupemutuel.io/plateforme-front-office/assures/gmapp/coverage/lcov.info]
11:51:02.458 DEBUG: Unresolved paths:
/builds/GDbogi_A/1/groupemutuel.io/plateforme-front-office/assures/gmapp/src/modules/@docs/producer/store/actions.js
/builds/GDbogi_A/1/groupemutuel.io/plateforme-front-office/assures/gmapp/src/modules/@docs/producer/store/constants.js
/builds/GDbogi_A/1/groupemutuel.io/plateforme-front-office/assures/gmapp/src/modules/@docs/producer/store/reducers.js
... 

It looks like the file paths in your coverage report don’t match the file paths analysis is seeing.

 
Ann

1 Like

Thanks for your quick answer @ganncamp !

Ok that’s certainly because I run the tests on a specific job and the analysis on a subsequent job in Gitlab…

I could merge those 2 jobs but I didn’t want to at the begining… This is because I’ll use a nodeJS specific image for the build and your sonarsource/sonar-scanner-cli:4.7 image for Sonar analysis…

Do you have a recommendation on how to proceed ?

Thanks a lot,

Grég

Hi Greg,

(Sorry about the missing accent, AmE keyboard :flushed:)

One thing you could do is normalize the paths in the report to be relative to project root. That ought to be both automatable and readily understood by analysis…

 
Ann

Thanks @ganncamp

I took the way to merge the two jobs and it works well now.
Thanks for your support.

For someone who would like to use the same way, here is what I did:
As said I use a simple NodeJS image for the build.

  • In my package.json, I added a script :
"sonar": "sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME  -Dsonar.projectKey=YOUR_PROJECT_KEY -Dsonar.organization=YOUR_SONAR_ORGANIZATION",
  • In my .gitlab-ci.yaml file, I added those 2 lines:
    - yarn global add sonarqube-scanner
    - yarn sonar

Best,

Grég

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.