# Code coverage not detected by SonarCloud scan

**URL:** <https://community.sonarsource.com/t/code-coverage-not-detected-by-sonarcloud-scan/105895>\
**Category:** SonarQube Cloud\
**Tags:** reports, javascript, sonarqube-cloud, coverage, scanner\
**Created:** [December 12, 2023, 3:42pm UTC](https://community.sonarsource.com/t/code-coverage-not-detected-by-sonarcloud-scan/105895 "2023-12-12T15:42:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xoib](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/xoib/32/14306_2.png) [@Xoib](https://community.sonarsource.com/u/Xoib)\
**Post date:** [December 12, 2023, 3:42pm UTC](https://community.sonarsource.com/t/code-coverage-not-detected-by-sonarcloud-scan/105895/1 "2023-12-12T15:42:57Z")

</div>

Hello,

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

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/b/b/bbd399c6eeeec1880328250ddff01d8e41dcf30b.png)

![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/2/d/2d9070c06fffea6d17f5e10e6377a99b056e97dc.png)

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

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/8/4/8416719d1c0b48c6db50782a76f17d1d015baeca.jpeg)

Our setup is the following:  
Github sonar workflow

```auto
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

```auto
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):

```auto
{
    "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](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/3/7/37f9d95059d36412a5c6747871f667326d511d41.jpeg)

Any help is greatly appreciated.

Thank you!

---

<div class="post-metadata">

**Author:** ![ismail.cherri](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ismail.cherri/32/39688_2.png) [@ismail.cherri](https://community.sonarsource.com/u/ismail.cherri)\
**Post date:** [December 12, 2023, 4:26pm UTC](https://community.sonarsource.com/t/code-coverage-not-detected-by-sonarcloud-scan/105895/2 "2023-12-12T16:26:12Z")

</div>

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](https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/javascript-typescript-test-coverage/#adding-coverage-to-your-build-process) and [here](https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/test-coverage-parameters/#javascripttypescript)

Regards,  
Ismail

---

<div class="post-metadata">

**Author:** ![Xoib](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/xoib/32/14306_2.png) [@Xoib](https://community.sonarsource.com/u/Xoib)\
**Post date:** [December 13, 2023, 3:52pm UTC](https://community.sonarsource.com/t/code-coverage-not-detected-by-sonarcloud-scan/105895/4 "2023-12-13T15:52:38Z")

</div>

Hello @ismail.cherri ,

I did indeed check that, and yes it finds it :  
 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/4/d/4dfd5babe9b8d48ec7a14f4df0a23e7d26b9df56.png)

It’s my last screenshot in my previous post.

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

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/9/e/9e0b361988f4ce1ed524f721deb700f25bfaae56.png)

---

<div class="post-metadata">

**Author:** ![ismail.cherri](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ismail.cherri/32/39688_2.png) [@ismail.cherri](https://community.sonarsource.com/u/ismail.cherri)\
**Post date:** [December 14, 2023, 2:52pm UTC](https://community.sonarsource.com/t/code-coverage-not-detected-by-sonarcloud-scan/105895/5 "2023-12-14T14:52:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Xoib](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/xoib/32/14306_2.png) [@Xoib](https://community.sonarsource.com/u/Xoib)\
**Post date:** [December 15, 2023, 9:08am UTC](https://community.sonarsource.com/t/code-coverage-not-detected-by-sonarcloud-scan/105895/6 "2023-12-15T09:08:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ismail.cherri](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ismail.cherri/32/39688_2.png) [@ismail.cherri](https://community.sonarsource.com/u/ismail.cherri)\
**Post date:** [December 15, 2023, 9:22am UTC](https://community.sonarsource.com/t/code-coverage-not-detected-by-sonarcloud-scan/105895/7 "2023-12-15T09:22:38Z")

</div>

Hey!

I’m glad it worked out for you eventually.

Regards,  
Ismail
