Not able to get code coverage on sonar portal

Hello,

I am not able to get sonarsource/sonarqube-scan-action@master to read code coverage lcov.info report.

It says

INFO: Analysing [/github/workspace/./__tests__/coverage/lcov.info]
WARN: Could not resolve 232 file paths in [/github/workspace/./__tests__/coverage/lcov.info]

Below is the workflow file & We are also checking in step “Debug lcov.info file” the lcov.info report content and it seems alright.

on:
  workflow_dispatch:
  push:
    branches:
      - Branchname
  pull_request:
    branches:
      - Branchname
jobs:
  sonarscan:
    name: sonarscaning
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Install dependencies
        run: |
            yarn install
            cd __tests__
            yarn install     

      - name: Test and coverage
        run: |
             cd __tests__
             yarn test
             ls
			 
      - name: Test & coverage Report
        run: |
             cd __tests__
             pwd
             ls
             cd coverage
             pwd
             ls
			 
      - name: Debug lcov.info file
        run: | 
            cd __tests__/coverage
            cat lcov.info   
            pwd     
            ls 

      - uses: sonarsource/sonarqube-scan-action@master
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

      - name: SonarQube Quality Gate check
        id: sonarqube-quality-gate-check
        uses: sonarsource/sonarqube-quality-gate-action@master
        # Force to fail step after specific time.
        # timeout-minutes: 5
        env:
         SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
         SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} ```



Below is what our sonar-project.properties file look like:
``
sonar.projectKey=XXXXXXXXXXXXXXXXXXXX
sonar.javascript.lcov.reportPaths=./__tests__/coverage/lcov.info
sonar.testExecutionReportPaths=./__tests__/test-report.xml
sonar.sources=.
sonar.sourceEncoding=UTF-8
sonar.test.inclusions=**/*.spec.js,**/*.spec.ts,__test__/**/*.spec.js,__test__/sapImageProxy/*.spec.js

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    –Developer EditionVersion 10.4.1
  • how is SonarQube deployed: zip

Hey there.

What is yarn test ultimately invoking? Stated another way, what are you using to run the tests and generate the coverage, and what configuration are you using?

Hi Colin,

Thanks for you reply. Actually, yarn test basically runs the script called ‘test’ from package.json which is “test”: “jest --coverage --config=jest.config.js --rootDir=…/ --verbose”

Configuration for jest is to determine from where to take the tests, what components to cover, what to ignore and so on.

Below is the configuration:

module.exports = {
  globals: {
    'ts-jest': {
      tsConfig: 'tsconfig.jest.json'
    }
  },
  preset: 'ts-jest/presets/js-with-babel',
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/$1',
    '^~/(.*)$': '<rootDir>/$1',
    '^vue$': 'vue/dist/vue.common.js'
  },
  moduleFileExtensions: ['js', 'vue', 'json', 'ts', 'tsx'],
  transform: {
    '^.+\\.js$': 'babel-jest',
    '.*\\.(vue)$': 'vue-jest',
    '^.+\\.(t)s$': 'ts-jest'
  },
  collectCoverage: true,
  collectCoverageFrom: [
    '<rootDir>/components/**/*.vue',
    '<rootDir>/pages/**/*.vue',
    '<rootDir>/plugins/**/*.ts',
    '<rootDir>/serverMiddleware/**/*.ts'
   
  ],
  coverageDirectory: '<rootDir>/__tests__/coverage',
  testMatch: ['<rootDir>/__tests__/**/**/*spec.[t|j]s?(x)', '<rootDir>/__tests__/**/*spec.[t|j]s?(x)'],
  testPathIgnorePatterns: ['<rootDir>/__tests__/e2e/'],
  testResultsProcessor: "jest-sonar-reporter",
  coverageReporters: ['html', 'json', 'text-summary', 'lcov', 'cobertura'],
  setupFiles: ['<rootDir>/__tests__/settings/setup.jest.ts'],
  modulePathIgnorePatterns: ["<rootDir>/__0unused_tests_/", "<rootDir>/~partytown/", "<rootDir>/static/"]
};

// ,'<rootDir>/__tests__/settings/setEnvVars.js'

Hello Team,

Can someone please help us here?
SOnar is not able to read the lcov.info even though it contains data init.

Hey there.

Please don’t repeatedly bump threads.

I created a topic, when can I expect a response?

This is an open community with people volunteering their free time to provide assistance. We’re eager to contribute to the community, but you are not guaranteed a fast response.

Be patient

  • Wait a few days before bumping a topic that hasn’t received a response.
  • Do not @name mention individuals not involved in the topic.

Contribute as much as you expect to receive

  • Contribute to the community (helping others) as much as you expect to receive help.

It is not a replacement for more structured support

  • If you need SLAs, guaranteed response, privacy, SonarSource also offers Commercial Support.

Hey @rohit.pandey

Sorry for coming back so late.

In your logs, you should see some specific file paths that are being ignored:

DEBUG: Unresolved paths:
assets/Segmentation.js

Some of these are probably files you recognize, which you have written tests on.

There are likely also other references to these file paths in the logs, such as whether or not they’ve been excluded.

DEBUG: File '/github/workspace/assets/Segmentation.js' is excluded by the scm ignore settings.

I suggest you select a file that’s being unresolved and see if it’s showing up anywhere else in your DEBUG level analysis logs (you can add this to your sonarqube-scan-action):

    args: >
      -Dsonar.verbose=true

In any case, even without a specific message (like the file being excluded by SCM settings) it would be interesting to see what path is identified by the coverage report, vs. when the file is being indexed.