Sonar reporting 0 coverage despite having lcov.info file

version: 7.9.1
testing framework: jest/nyc

We have an application that uses Vue and TS. The directory structure is bellow. When I run nyc --silent jest --coverage && nyc report --clean --exit it runs the jest tests properly (where there I can see coverage reported) and data is being populated correctly in the lcov file. However, when I check the dashboard it still says 0 precent coverage…
Not really sure what’s going on?

build/
  nyc_coverage/
    lcov.info
src/
  components/
      example/
         __tests__/ 
           example.spec.ts
         example.vue
         example.ts
         example.css

our sonar-project.properties file:

sonar.sources=src
sonar.exclusions= **/__mocks__/**/*,**/*.spec.ts
sonar.tests=src
sonar.test.inclusions=**/*.spec.ts
sonar.typescript.lcov.reportPaths=./build/nyc_coverage/lcov.info

example entry in lcov.info

SF:/Users/Annette.Lin@ibm.com/Desktop/mailIBM/web/src/components/PrivacyNoticeBanner/PrivacyNoticeBanner.ts
FNF:0
FNH:0
DA:1,2
DA:3,2
DA:6,0
DA:12,0
DA:13,0
LF:5
LH:2
BRF:0
BRH:0
end_of_record
1 Like

Greetings Annette,

Can you share your analysis logs (the result of executing sonar-scanner)?

Best regards,

Colin

1 Like

Hey Colin,

Thanks for helping. See below for full logs:

INFO: Scanner configuration file: /usr/bin/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /tmp/git/sonar-project.properties
INFO: SonarQube Scanner 4.0.0.1744
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 4.4.0-166-generic amd64
INFO: User cache: /root/.sonar/cache
INFO: SonarQube server 7.9.1
INFO: Default locale: "en_US", source code encoding: "US-ASCII" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=467ms
INFO: Server id: 78215A17-AWtTKrbzni_AItFD7yMA
INFO: User cache: /root/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=119ms
INFO: Load/download plugins (done) | time=14639ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=5ms
INFO: Project key: mailatibmsignup/web
INFO: Base dir: /tmp/git
INFO: Working dir: /tmp/git/.scannerwork
INFO: Load project settings for component key: 'mailatibmsignup/web'
INFO: Load project settings for component key: 'mailatibmsignup/web' (done) | time=97ms
INFO: Load project branches
INFO: Load project branches (done) | time=94ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=97ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=2ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=137ms
INFO: Load active rules
INFO: Load active rules (done) | time=3016ms
INFO: Branch name: dev, type: short living
INFO: SCM collecting changed files in the branch
INFO: SCM collecting changed files in the branch (done) | time=223ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/__mocks__/**/*, **/*.spec.ts, **/*.spec.ts
INFO:   Included tests: **/*.spec.ts
INFO: 143 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for css: Sonar way
INFO: Quality profile for js: Sonar way Recommended
INFO: Quality profile for ts: Sonar way recommended
INFO: ------------- Run sensors on module mailatibmsignup/web
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=85ms
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/root/.sonar/cache/a89f1943fc75b65becd9fb4ecab8d913/sonar-tsql-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: Sensor SonarCSS Metrics [cssfamily]
INFO: Sensor SonarCSS Metrics [cssfamily] (done) | time=173ms
INFO: Sensor SonarCSS Rules [cssfamily]
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=2430ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=3ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=112ms
INFO: Sensor SonarTS [typescript]
INFO: Analyzing 68 typescript file(s) with the following configuration file /tmp/git/tsconfig.json
INFO: 68 files analyzed out of 68
INFO: Sensor SonarTS [typescript] (done) | time=4762ms
INFO: Sensor SonarTS Coverage [typescript]
INFO: Analysing [/tmp/git/./build/nyc_coverage/lcov.info]
WARN: Could not resolve 4 file paths in [/tmp/git/./build/nyc_coverage/lcov.info], first unresolved path: /tmp/git/.eslintrc.js
INFO: Sensor SonarTS Coverage [typescript] (done) | time=3ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
INFO: Sensor SonarJS [javascript]
INFO: 23 source files to be analyzed
INFO: Sensor SonarJS [javascript] (done) | time=434ms
INFO: Sensor ESLint-based SonarJS [javascript]
INFO: 23/23 source files have been analyzed
INFO: 23 source files to be analyzed
INFO: Sensor ESLint-based SonarJS [javascript] (done) | time=1686ms
INFO: 23/23 source files have been analyzed
INFO: Sensor JavaSecuritySensor [security]
INFO: Reading type hierarchy from: /tmp/git/.scannerwork/ucfg2/java
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /tmp/git/.scannerwork/ucfg2/java
INFO: No UCFGs have been included for analysis.
INFO: Sensor JavaSecuritySensor [security] (done) | time=5ms
INFO: Sensor CSharpSecuritySensor [security]
INFO: Reading type hierarchy from: /tmp/git/ucfg_cs2
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /tmp/git/ucfg_cs2
INFO: No UCFGs have been included for analysis.
INFO: Sensor CSharpSecuritySensor [security] (done) | time=0ms
INFO: Sensor PhpSecuritySensor [security]
INFO: Reading type hierarchy from: /tmp/git/.scannerwork/ucfg2/php
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /tmp/git/.scannerwork/ucfg2/php
INFO: No UCFGs have been included for analysis.
INFO: Sensor PhpSecuritySensor [security] (done) | time=0ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=19ms
INFO: 51 files had no CPD blocks
INFO: Calculating CPD for 40 files
INFO: CPD calculation finished
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=4ms
INFO: Analysis report generated in 105ms, dir size=178 KB
INFO: Analysis report compressed in 119ms, zip size=86 KB
INFO: Analysis report uploaded in 295ms
INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarqube.sl.bluecloud.ibm.com/dashboard?id=mailatibmsignup%2Fweb&branch=dev&resolved=false
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarqube.sl.bluecloud.ibm.com/api/ce/task?id=AW6kckveMpekxdX2Dsoh
INFO: Analysis total time: 18.697 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 37.389s
INFO: Final Memory: 32M/110M
INFO: ------------------------------------------------------------------------

It’s curious to see:

INFO: Analysing [/tmp/git/./build/nyc_coverage/lcov.info]
WARN: Could not resolve 4 file paths in [/tmp/git/./build/nyc_coverage/lcov.info], first unresolved path: /tmp/git/.eslintrc.js

but I’m not sure if that’s the true source of the problem?

1 Like

Hi,

I see absolute paths in the report (/Users/Annette.Lin@ibm.com/Desktop/mailIBM/web/src/components/PrivacyNoticeBanner/PrivacyNoticeBanner.ts). Are you running analysis at the same location where you generate the report? If not than absolute path might not be precise anymore.

How many files do you have in the report? According to log only 4 files were not recognized, then for the rest you should have coverage, so it’s weird that you have 0 at the end.

Hey Lena,

So this is when I run tests locally. We have a separate devops process internally from a separate team the manages the entire build (which part of it involves running sonar scanner). I have to get them to cat the contents of the lcov file. My hunch is that it either might be getting an outdated/incorrect on because there’s no actual reference to eslintrc.js when I check the lcov.info file that’s locally for me.

As a separate note, I do also have .vue extensions in the coverage report since this is a vue/ts app). I’m curious as to whether that might be an issue as well since I don’t just have .ts in there, which causes Sonar to freak out?

SF:/Users/Annette.Lin@ibm.com/Desktop/mailIBM/web/src/views/Healthcheck/Healthcheck.vue
FNF:0
FNH:0
DA:6,1
LF:1
LH:1
BRF:0
BRH:0
end_of_record
TN:
SF:/Users/Annette.Lin@ibm.com/Desktop/mailIBM/web/src/views/IntroPage/IntroPage.ts
FNF:0
FNH:0
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:6,1
DA:14,0
DA:19,0
DA:23,0
LF:8
LH:5
BRF:0
BRH:0
end_of_record

Hi,

Vue files should not make any trouble provided that lines are correct.

To have a consistent reproducer could you share the logs of your local analysis, lcov report used for that analysis and the coverage in SQ after this analysis?

Ended up solving the issue actually! Turns out nyc was never needed as Jest already has istanbul libraries included to provide coverage. Having nyc interfered with the way our tests were being run and ended up overriding our lcov.info file every time when we were deploying containers!

1 Like