Cannot read coverage report file, expecting standard SimpleCov JSON formatter output

Recently, I have configured Jenkins and sonar for my ruby project.
Following are the below Jenkins and error details :

 ERROR: Cannot read coverage report file, expecting standard SimpleCov JSON formatter output: '/home/jenkins/agent/workspace/ABC_PR-1239/coverage/coverage.json'

Note:

  • I can able to see the generated file at location coverage/coverage.json

  • SonarQube verison - 0.21.2

  • Property file contains

sonar.exclusions=**node_modules/**,**/build_files/**,**/spec/**,**/test/**,**/features/**,**/helm/**,**/tmp/**,**/vendor/**
sonar.organization=ABC
sonar.projectKey=abc
sonar.projectName=abc
sonar.ruby.coverage.reportPaths=coverage/coverage.json
sonar.sources=.
sonar.sourceEncoding=UTF-8
sonar.tests=.
sonar.test.inclusions=**/test/**
sonar.verbose=true
  • setting in spec_helper.rb
require 'simplecov-json'
require 'simplecov_json_formatter'
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
SimpleCov.start do
  enable_coverage :branch
end
  • In coverage directory I can see below files,
    Screenshot 2022-12-12 at 2.24.01 PM

What I want,

  • I have tried in my ways but nothing worked.
  • I expect my coverage results to reflect on sonar dashboard.

It sounds like something is wrong with the contents of /home/jenkins/agent/workspace/ABC_PR-1239/coverage/coverage.json’. Does it look as expected to you?

This isn’t a valid SonarQube Version – check the footer of your SonarQube instance for the true version and report back!

Thanks for your reply.

Yes, the path which I have mentioned it’s Jenkin path.
/home/jenkins/agent/workspace/ABC_PR-1239/
and on root of my project I am generating coverage.json file
coverage/coverage.json

If I made any changes to this path then it gives below error,

ERROR: SimpleCov report not found: ‘coverage/coverage.json’

Below are the more details,

simplecov (0.21.2)
simplecov-html (0.12.3, 0.10.2)
simplecov-json (0.2.3)
simplecov-lcov (0.8.0)
simplecov-rcov (0.2.3)
simplecov_json_formatter (0.1.4, 0.1.3)

Can I get any example json file in standard SimpleCov JSON format. I will verify it by passing this.

Here is my generated coverage.json file for your reference.

coverage.json (4.3 KB)

Thanks. Let’s step back to this question again:

This I found in the footer.

  • Enterprise Edition
  • Version 9.2.4 (build 50792)
  • LGPL v3

Thanks. I would have expected a file that looks more like this one:

{
  "meta": {
    "simplecov_version": "0.20.0"
  },
  "coverage": {
    "/Absolute/Path/To/file1.rb": {
      "lines": [
        1,
        1,
        2,
        null,
        "ignored",
        1,
        0
      ],
      "branches": [
      ]
    }
  }
}

I’m not quite sure how you’ve landed on another format, except that the output you’ve shared seems to match this JSON formatter rather than this one (which appears to be more closely tied to the simplecov project, and produces the expected format).

Yes, I have used gem simplecov-json and it is generating this JSON format. I will try by removing it and will check default simplecov’s generated JSON format.

Hi Colin, After removing gem simplecov-json I can able to get data in suggested json format. Here, is file for your reference. But, still I am not able to see the coverage details in the dashboard. In logs, I didn’t find any error messages. Can you please help me what I am missing here.
coverage.json (12.9 KB)

Can someone help me on the above issue.

Can you share the full logs from analysis (the output from the scanner, where you are now passing the new coverage report), and a screenshot of where you see 0% coverage being reported in SonarQube?

Hi Colin, This issue is fixed after merging in master branch. Now, I can see the code coverage. Thanks for your help
.

1 Like