Code coverage not being displayed on SonarCloud even with all config set

Project info: Front End with JS/React
I have followed all the instructions to integrate sonarCloud scan with my front end project from this documentation
I followed everything through, the integration has been done successfully and I see sonarcloud being triggered on github actions.
However when I go to sonarCloud dashboard it is not being displayed.
I have an example of the projects we have on the screenshot: Project 1 displays the coverage, project 2 (the one I’ve been working on) does not display. And that’s what I’m trying to get:

  • I already double checked all the config added: I’ve added a sonar-project.properties file to the root that looks like this (update the info according to my organization):
sonar.organization=abc
sonar.projectKey=Company_project_react
sonar.sources= src
sonar.exclusions= src/components/atoms/HeadDocument/HeadDocument.js, src/components/atoms/NextScriptDocument/NextScriptDocument.js
sonar.javascript.lcov.reportPaths=src/coverage/lcov.info
sonar.typescript.tsconfigPath=src/tsconfig.json

I compared with what has been done to project 1, and what I did was exactly the same, but for project 2 doesn’t work.
I have added to .github/workflows/test.yml the additional sonarConfig:

name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v1.6
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        with:
          args: >
            -Dsonar.pullrequest.key=${{ github.event.number }}
            -Dsonar.pullrequest.branch=${{ github.HEAD_REF }}
            -Dsonar.pullrequest.base=${{ github.BASE_REF }}
            -Dsonar.pullrequest.github.repository=${{ github.repository }}
            -Dsonar.scm.provider=git

Anyway, I don’t know what else to do.
So appreciate some help please :pray:

Hey there.

Even if 0.0% coverage was being reported, it should still show up on your dashboard.

So let’s assume for a moment that coverage is being imported correcty.

The only two ways to have null coverage reported would be

  • Zero Executable Lines (unlikely if your project has Javascript in it)
  • All files are being excluded from coverage.

Let’s consider the second for a moment. In your scanner logs you should have some logs like this, can you see if there are any files being marked as excluded sources for coverage?

INFO: Project configuration:
INFO:   Excluded sources: **/build-wrapper-dump.json, **/*.spec.ts
INFO:   Included tests: **/*.spec.ts
INFO:   Excluded sources for coverage: **/*
INFO: 1 file indexed

Hello Colin, thank you for your reply :slightly_smiling_face:
On my project we have configured that the coverage files to be excluded as the following (we use jest for it):

collectCoverageFrom: [
        "src/components/**/*.js",
        "!src/components/atoms/HeadDocument/HeadDocument.js",
        "!src/components/atoms/NextScriptDocument/NextScriptDocument.js",
    ],

And this is how the file is sonar-project.properties file is currently:

sonar.organization=abc
sonar.projectKey=Company_project_react

sonar.sources= src/components
sonar.exclusions= src/components/atoms/HeadDocument/HeadDocument.js, 
src/components/atoms/NextScriptDocument/NextScriptDocument.js

sonar.javascript.lcov.reportPaths=src/coverage/lcov.info
sonar.typescript.tsconfigPath=src/tsconfig.json

So I don’t see why would that be the source of the coverage not being displayed :confused:

Hey there.

I appreciate the additional information, but I really suggest stepping back to the previous question about what you see in the scanner logs.

Sorry I misunderstood your question.
I took a screenshot of what I have in the logs regarding what you asked, here you go:

I also noticed in the logs the following:

Update: I merged this to our develop branch, once I did, the 0.0% appeared on sonar dashboard - At least some progress :sweat_smile:
But when I check the logs I still see the coverage pointing for jacoco. And I don’t get it why, since the path I passed is correct.

Hey there.

The JaCoco XML Report Importer will show up on every analysis despite what languages/analysis parameters are passed. But there should be a section specific to import of javascript LCOV reports.

INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: Analysing [/home/vsts/work/1/s/test-results/coverage/lcov.info]
INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=48ms

Do you see something like this in your log files, and any associated warnings/errors?

This is the closest I could find to the example you just shared on line 85:

@Colin to test a theory here, I added to the yml file - run: ls (after the action- run: yarn test:coverage)
and pushed the changes. With that I noticed that the the folder coverage was not created in the step before, and that’s why it’s null.
Then I manually deleted the folder coverage and ran yarn test:coverage -u

This way the folder is generated but we know that this is not the way.

How to solve that? I still don’t know :sweat_smile:

Hey there.

It’s best if we stay focused on a single topic – let’s make sure that the Sensor JavaScript/TypeScript Coverage is running (that means that the scanner has identified a value is being passed to sonar.javascript.lcov.reportPaths) and then, once that’s taken care of, return to making sure the coverage report is generated in the right place (which is not much of a SonarCloud issue).

I’m a bit worried your sonar-project.properties file might be in a werid state, or that settings are being passed somewhere you aren’t aware of. For example, did you notice that here;

sonar.exclusions is tacked onto Excluded sources for coverage? That shouldn’t be happening.

Let me suggest this:

  • Please make sure that all values in your sonar-project.properties file are configured correctly, this means removing the spaces between <analysis paramter>= value and that each anlalysis parameter takes up one line (it looks like your second file for sonar.exclusions is on a new line)

This would look something like:

sonar.organization=abc
sonar.projectKey=Company_project_react

sonar.sources=src/components
sonar.exclusions=src/components/atoms/HeadDocument/HeadDocument.js,src/components/atoms/NextScriptDocument/NextScriptDocument.js

sonar.javascript.lcov.reportPaths=src/coverage/lcov.info
sonar.typescript.tsconfigPath=src/tsconfig.json
  • Under project level Administration > Background Tasks, open up the SonarScanner context of an analysis that should have coverage reported and paste it here.

@Colin I update my sonar-project.properties file as you suggested. Making sure there are no spaces. Now it looks like this (I adjusted the sonar.sources only for src)

sonar.organization=abc
sonar.projectKey=Company_project_react

sonar.sources=src
sonar.exclusions=src/components/atoms/HeadDocument/HeadDocument.js, src/components/atoms/NextScriptDocument/NextScriptDocument.js

sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.typescript.tsconfigPath=src/tsconfig.json

And here’s the screenshot as requested from Administration > Background Tasks:

Thanks again for your help so far :blush:

@alineborak You’ll need to actually open up the Scanner Context (as pointed to by an arrow in the screenshot) and paste it here.

SonarCloud plugins:
  - IaC Code Quality and Security 1.4.0.1294 (iac)
  - PL/SQL Code Quality and Security 3.6.1.3873 (plsql)
  - Scala Code Quality and Security 1.8.3.2219 (sonarscala)
  - C# Code Quality and Security 8.33.0.40503 (csharp)
  - Vulnerability Analysis 9.2.0.14426 (security)
  - Java Code Quality and Security 7.6.0.28201 (java)
  - HTML Code Quality and Security 3.5.0.3009 (web)
  - Flex Code Quality and Security 2.6.2.2641 (flex)
  - XML Code Quality and Security 2.5.0.3376 (xml)
  - VB.NET Code Quality and Security 8.33.0.40503 (vbnet)
  - Swift Code Quality and Security 4.3.2.5043 (swift)
  - CFamily Code Quality and Security 6.28.0.39490 (cpp)
  - Python Code Quality and Security 3.8.0.8883 (python)
  - Go Code Quality and Security 1.8.3.2219 (go)
  - JaCoCo 1.1.1.1157 (jacoco)
  - Kotlin Code Quality and Security 2.8.0.1093 (kotlin)
  - Mercurial 1.1.2 (scmmercurial)
  - T-SQL Code Quality and Security 1.5.1.4340 (tsql)
  - Apex Code Quality and Security 1.8.3.2219 (sonarapex)
  - JavaScript/TypeScript Code Quality and Security 8.7.0.17093 (javascript)
  - Ruby Code Quality and Security 1.8.3.2219 (ruby)
  - Vulnerability Rules for C# 9.2.0.14426 (securitycsharpfrontend)
  - Vulnerability Rules for Java 9.2.0.14426 (securityjavafrontend)
  - License for SonarLint 8.0.0.25523 (license)
  - Vulnerability Rules for JS 9.2.0.14426 (securityjsfrontend)
  - COBOL Code Quality 4.6.2.4876 (cobol)
  - Vulnerability Rules for Python 9.2.0.14426 (securitypythonfrontend)
  - PHP Code Quality and Security 3.22.0.8482 (php)
  - ABAP Code Quality and Security 3.9.1.3127 (abap)
  - Configuration detection fot Code Quality and Security 1.1.0.185 (config)
  - Vulnerability Rules for PHP 9.2.0.14426 (securityphpfrontend)
Global server settings:
  - email.from=noreply@sonarcloud.io
  - email.fromName=SonarCloud
  - email.prefix=[SonarCloud]
  - node_10_end_of_support_date=1620604800000
  - node_10_grace_period_termination_date=1621814400000
  - sonar.auth.bitbucket.enabled=true
  - sonar.auth.microsoft.enabled=true
  - sonar.core.id=1BD809FA-AWHW8ct9-T_TB3XqouNu
  - sonar.core.serverBaseURL=https://sonarcloud.io
  - sonar.core.startTime=2021-12-15T11:20:40+0100
  - sonar.dbcleaner.weeksBeforeDeletingAllSnapshots=260
  - sonar.dbcleaner.weeksBeforeKeepingOnlyOneSnapshotByMonth=4
  - sonar.dbcleaner.weeksBeforeKeepingOnlyOneSnapshotByWeek=1
  - sonar.global.exclusions=**/build-wrapper-dump.json
  - sonar.lf.enableGravatar=true
  - sonar.lf.logoWidthPx=105
  - sonar.maintenance_mode.link=https://sonarcloud.statuspage.io/incidents/4y1k6q1wsy4v
  - sonar.organizations.anyoneCanCreate=true
  - sonar.organizations.createPersonalOrg=true
  - sonar.plsql.file.suffixes=sql,tab,pkb
  - sonar.tsql.file.suffixes=.tsql
Project server settings:
  - sonar.autoscan.enabled=false
  - sonar.coverage.exclusions="src/components/atoms/HeadDocument/HeadDocument.js, src/components/atoms/NextScriptDocument/NextScriptDocument.js",sonar.exclusions
  - sonar.javascript.lcov.reportPaths=src/coverage/lcov.info
  - sonar.scm.disabled=true
  - sonar.typescript.tsconfigPath=src/tsconfig.json
Project scanner properties:
  - sonar.exclusions=src/components/atoms/HeadDocument/HeadDocument.js, src/components/atoms/NextScriptDocument/NextScriptDocument.js
  - sonar.host.url=https://sonarcloud.io
  - sonar.javascript.lcov.reportPaths=coverage/lcov.info
  - sonar.organization=abc
  - sonar.projectBaseDir=/github/workspace
  - sonar.projectKey=Company_project_react
  - sonar.pullrequest.base=
  - sonar.pullrequest.branch=
  - sonar.pullrequest.github.repository=Company_project_react
  - sonar.pullrequest.key=
  - sonar.scanner.app=ScannerCLI
  - sonar.scanner.appVersion=4.6.2.2472
  - sonar.scm.provider=git
  - sonar.sourceEncoding=UTF-8
  - sonar.sources=src/components
  - sonar.typescript.tsconfigPath=src/tsconfig.json
  - sonar.working.directory=/github/workspace/.scannerwork

Update: This problem has not been solved yet, so if anyone from SonarCloud community can help, that would be really appreciated :innocent:

Hi Colin,
I have two repos, linked to two different Sonarcloud projects. Each project has the same configuration in SonarCloud. I’m using Bitbucket Pipelines to scan using this pipe (Bitbucket), pipeline YAML files are identical for both repos.

The backend project, where coverage works, has this in the Scanner Context:

Project server settings:
 sonar.javascript.lcov.reportPaths=coverage/lcov.info

while the front end project, where the coverage does not work, is missing that line.

Any help would be appreciated

Explicitly setting

          - pipe: sonarsource/sonarcloud-scan:1.4.0
            variables:
              EXTRA_ARGS: -Dsonar.javascript.lcov.reportPaths=\"coverage/lcov.info\"

in the bitbucket-pipeline.yml works, now I see the coverage correctly. I’m not sure why I have to set it for one repo, but not the other.

Hey ther.e

I would imagine that for the backend project, you have something set in the project level Administration > General Settings > Languages > Javascript/Typescript while for the latter project you don’t. It’s perfectly valid to set this either in the project administration or as an analysis parameter.

That is correct! Thanks. Interesting to note, in the backend project in Sonarcloud, when I navigate to

Administration > General Settings > Languages > Javascript/Typescript

it shows me this:

even though there is a configuration set up. So for both projects I see the same view in the Languages settings until I actually select Javascript/Typescript.

Kind of a confusing UX, IMO.

Thanks for the feedback! I’ll pass it on.