Code coverage not detected by SonarCloud scan

Hello,

We are trying to get code coverage information on SonarCloud dashboard and in the Github PR :

image

As you can see, it detect 0% coverage but we do have some coverage :

Our setup is the following:
Github sonar workflow

name: Sonar
on:
  push:
    branches:
      - develop
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  sonarcloud:
    name: SonarCloud
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
          token: ${{ secrets.PAT_TOKEN }}
      - name: Use Node.js 12
        uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm run install:all
      - run: npm run cover
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

sonar-project.properties

sonar.projectKey=******
sonar.organization=******

sonar.projectName=******
sonar.projectVersion=1.0

sonar.sources=src/**/cartridges/**/cartridge/
sonar.exclusions=src/**/cartridges/app_storefront_base/**/*, metadata/**/*, node_modules/**, .idea/**/*, .vscode/**/*, test/reports/**/*, **/jobs/decisionManager.js, **/jobsteps/OrderStatus.js, test/integration/**/*, .scannerwork/**/*, src/submodules/**/*
sonar.javascript.lcov.reportPaths=coverage/lcov.info,test/reports/coverage/lcov.info
sonar.coverage.exclusions=test/**/*, src/**/cartridges/**/cartridge/controllers/**

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

package.json (relevant part only):

{
    "name": "****",
    "version": "0.0.1",
    "description": "New overlay cartridge",
    "main": "index.js",
    "scripts": {
        "install:all": "npm install && node .utils/install.js all",
        "install:cartridge": "node .utils/install.js cartridge=%npm_config_name%",
        "test": "sgmf-scripts --test 'test/unit/**/*.js'",
        "cover": "sgmf-scripts --cover 'test/unit/**/*.js' --exclude app_path.js",
        "cover:report": "istanbul cover node_modules/mocha/bin/_mocha --dir test/reports/coverage/ -- -R spec --recursive test/unit/**/*.js",
        "git:submodule:update": "git submodule update --init --recursive",
        "dev": "webpack --env.dev --env.map=%npm_config_source_map%",
        "build": "webpack --env.dev=false",

Relevant github action workflow part:
image

Any help is greatly appreciated.

Thank you!

Hi @Xoib

Welcome to the Sonar Community,

From the scan report, the scanner cannot find the lcov.info file. You need to make sure that:

  1. Your coverage reporter tool produces an lcov.info file
  2. The sonar.javascript.lcov.reportPaths variable points to the correct folder in the github runner workspace. For example use ./covergage/... instead of coverage/... alone

More information can be found in the documentation here and here

Regards,
Ismail

Hello @ismail.cherri ,

I did indeed check that, and yes it finds it :
image

It’s my last screenshot in my previous post.

I tried a fix (with sed command) but it state the same WARN message :

Hey,

So in your last fix attempt, you replaced the path in the lcov file. Can you post some path examples in the lcov file before and after the fix? Feel free to redact file name, I’m just interested in the path.

Regards,
Ismail

Hello @ismail.cherri ,

After my last answer, I continued to mess with my sed command to fix the paths in lcov file and found the correct path replacement to make it work.

Thank you

1 Like

Hey!

I’m glad it worked out for you eventually.

Regards,
Ismail