No coverage information will be saved because all LCOV files cannot be found

  • SonarQube Enterprise 9.7.1, SonarScanner CLI v4.6.1.2450
  • We are trying to scan a Ext.JS project tests and provide code coverage reports
  • We’re using karma and jasmine
  • We are running SonarScanner CLI with the following property:
/d:sonar.javascript.lcov.reportPaths=./TestResults/coverage/lcov.info
  • We tried this too and had the same issue:
/d:sonar.javascript.lcov.reportPaths=TestResults/coverage/lcov.info
  • Issue:

[2022-11-24T13:48:36.994Z] 08:48:36.929 INFO: Sensor JavaScript/TypeScript Coverage [javascript]
[2022-11-24T13:48:36.994Z] 08:48:36.930 DEBUG: Property sonar.javascript.lcov.reportPaths is used.
[2022-11-24T13:48:36.994Z] 08:48:36.930 DEBUG: Using './TestResults/coverage/lcov.info' to resolve LCOV files
[2022-11-24T13:48:36.994Z] 08:48:36.959 INFO: No LCOV files were found using ./TestResults/coverage/lcov.info
[2022-11-24T13:48:36.994Z] 08:48:36.959 WARN: No coverage information will be saved because all LCOV files cannot be found.
[2022-11-24T13:48:36.994Z] 08:48:36.959 INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=30ms

Our karma.conf.js:

module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['jasmine'],

    plugins : [
        'karma-jasmine',
        'karma-phantomjs-launcher',
        'karma-coverage',
        'karma-junit-reporter'
    ],

    files: [
        'ext/build/ext-modern-all-debug.js',
        'setup-karma.js',

        { pattern: 'ext/**/*.*', watched: false, served: true, included: false},
        { pattern: 'app/**/*.js', watched: true, served: true, included: true },
        { pattern: 'specs/**/*.js', watched: false, served: true, included: true },
    ],

    // for now we're ignoring these files
    exclude: ['specs/model/*Spec.js',
                'specs/model/*Spec.js',
                'specs/model/*Spec.js',
                'specs/store/*Spec.js',
                'specs/store/*Spec.js'
    ],

    preprocessors: {
      'app/**/*.js': ['coverage'],
      'overrides/*.js': ['coverage']
    },

    reporters: ['junit', 'coverage', 'progress'],

    port: 9876,

    colors: true,

    logLevel: config.LOG_INFO,

    autoWatch: true,

    browsers: ['PhantomJS'],

    singleRun: true,

    concurrency: Infinity,

    captureTimeout : 60000,
    browserDisconnectTimeout : 60000,
    browserNoActivityTimeout : 60000,

    junitReporter: {
      outputDir: '../TestResults',
      suite: 'models',
      useBrowserName: false,
      xmlVersion: '1'
    },

    coverageReporter: {
      type: 'lcov',
      dir: '../TestResults/coverage',
      subdir: '.'
    },
  });
};

The project structure:

--root
  |---TestResults
  |    |----coverage
  |    |     |-----lcov.info
  |---Mobile.Ext
  |    |----apps // js files
  |    |----specs // tests
  |    |----karma.conf.js

The weirdest thing is that the lcov.info file exists on the folder when SonarScanner starts to run.

Any help would be greatly appreciated! Thank you in advance!

Hey there.

What directory are you initiating the SonarQube scan from? The root directory?

This will be the correct format.

Hi there!

Yeah, the SonarQube scan is been executed on the root directory. The sonar.sources is going through all the directories on the project.

Hey there.

Thanks.

I would suggest two things:

  • Supply the complete analysis logs (redacting sensitive info if necessary).
  • Not knowing the full details of your build, you might try printing the content of TestResults/coverage/lcov.info immediately before the scanner, just to be extra sure it exists at the right time. Something like cat TestResults/coverage/lcov.info

Hey!

So we figured out what was the main issue and I decided to share here hopping help someone… The lcov.info file was not the problem.

The further issue with SonarScan process was:

WARN: Could not resolve X file paths in...

It happens then without tsconfig.json or sonar.sources the pipeline is not able to find relative paths:

TN:
SF:Mobile.Ext\apps\Application.js
FN:8,(anonymous_0)
(...)

And instead, it needs an absolute path:

TN:
SF:C:\root\Mobile.Ext\apps\Application.js
FN:8,(anonymous_0)
(...)

So what we did to fix it was added to our build run batch a convert lcov path action:

$currentDirectory = Get-Location
$replacement = "SF:" + $currentDirectory + "\"
$content = Get-Content -Path 'TestResults\coverage\lcov.info'
$newContent = $content -replace 'SF:', $replacement
$newContent | Set-Content -Path 'TestResults\coverage\lcov.info'

With this, we’re able to fix all paths on lcov.info generated file before running SonarScan.

Thank you for your help!

The insight about the directory that Sonar Scan was initializing really got us on the right path :wink:

1 Like

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