codeclimate / test-reporter

Code Climate Test Reporter
MIT License
156 stars 76 forks source link

sum-coverage reporting incorrect total coverage #518

Open finn-orsini opened 1 year ago

finn-orsini commented 1 year ago

Description

The output of sum-coverage (following calls to format-coverage) is incorrectly reporting total coverage stats. Behavior appears in CI (github actions, ubuntu-22.04) and locally (mac osx 13.3).

Steps to Reproduce

Create the following files (which locally were generated from format-coverage of lcov files):

coverage-cypress.json

{
  "ci_service": {
    "branch": "finn_orsini_example",
    "build_identifier": "",
    "build_url": "",
    "commit_sha": "84fe3d6c048cf3a2233ca91109c59c89fbb462f9",
    "committed_at": 1692022071,
    "name": ""
  },
  "environment": {
    "gem_version": "3.4.10",
    "package_version": "",
    "pwd": "/Users/forsini/code/repo",
    "prefix": "/Users/forsini/code/repo",
    "rails_root": "",
    "reporter_version": "latest",
    "simplecov_root": ""
  },
  "git": {
    "branch": "finn_orsini_example",
    "head": "84fe3d6c048cf3a2233ca91109c59c89fbb462f9",
    "committed_at": 1692022071
  },
  "covered_percent": 44.6081319976429,
  "covered_strength": 0,
  "line_counts": {
    "missed": 940,
    "covered": 757,
    "total": 1697
  },
  "source_files": [
    {
      "blob_id": "07b162a33528600bc64ef8831f7526bec214ce4a",
      "coverage": "[]",
      "covered_percent": 0,
      "covered_strength": 0,
      "line_counts": {
        "missed": 0,
        "covered": 0,
        "total": 0
      },
      "name": "src/app/example.js"
    }
  ],
  "repo_token": ""
}

coverage-jest.json

{
  "ci_service": {
    "branch": "finn_orsini_example",
    "build_identifier": "",
    "build_url": "",
    "commit_sha": "84fe3d6c048cf3a2233ca91109c59c89fbb462f9",
    "committed_at": 1692022071,
    "name": ""
  },
  "environment": {
    "gem_version": "3.4.10",
    "package_version": "",
    "pwd": "/Users/forsini/code/repo",
    "prefix": "/Users/forsini/code/repo",
    "rails_root": "",
    "reporter_version": "latest",
    "simplecov_root": ""
  },
  "git": {
    "branch": "finn_orsini_example",
    "head": "84fe3d6c048cf3a2233ca91109c59c89fbb462f9",
    "committed_at": 1692022071
  },
  "covered_percent": 95.39007092198581,
  "covered_strength": 0,
  "line_counts": {
    "missed": 13,
    "covered": 269,
    "total": 282
  },
  "source_files": [
    {
      "blob_id": "07b162a33528600bc64ef8831f7526bec214ce4a",
      "coverage": "[null,null,null,null,null,null,null,null,null,null,null,8,8,null,null,null,null,9,null,8,8,null,null,null,null,8,null,null,null,null,null,8,null,1,1,null,null,8,null,8,8,null,null,null,null,null,8,null,8,null,null,8,null,null,6,6,null,6,3,null,null,null,null,null,null,null,null,3,null,null,null,null,null,null,null,null,null,3,null,null,null,null,null,null,null,null,null,null,8,null,0,null,null,null,null,null,null,null,0]",
      "covered_percent": 91.66666666666666,
      "covered_strength": 5.916666666666667,
      "line_counts": {
        "missed": 2,
        "covered": 22,
        "total": 24
      },
      "name": "src/app/example.js"
    }
  ],
  "repo_token": ""
}

Run the sum coverage command, i.e. ./cc-test-reporter sum-coverage coverage-cypress.json coverage-jest.json -p 2 -o coverage-total.json. View the total coverage report, which incorrectly reports that the example.js file has no coverage:

{
  "ci_service": {
    "branch": "finn_orsini_example",
    "build_identifier": "",
    "build_url": "",
    "commit_sha": "84fe3d6c048cf3a2233ca91109c59c89fbb462f9",
    "committed_at": 1692022071,
    "name": ""
  },
  "environment": {
    "gem_version": "3.4.10",
    "package_version": "",
    "pwd": "/Users/forsini/code/repo",
    "prefix": "/Users/forsini/code/repo",
    "rails_root": "",
    "reporter_version": "latest",
    "simplecov_root": ""
  },
  "git": {
    "branch": "finn_orsini_example",
    "head": "84fe3d6c048cf3a2233ca91109c59c89fbb462f9",
    "committed_at": 1692022071
  },
  "covered_percent": 44.6081319976429,
  "covered_strength": 0,
  "line_counts": {
    "missed": 940,
    "covered": 757,
    "total": 1697
  },
  "source_files": [
    {
      "blob_id": "07b162a33528600bc64ef8831f7526bec214ce4a",
      "coverage": "[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]",
      "covered_percent": 0,
      "covered_strength": 0,
      "line_counts": {
        "missed": 0,
        "covered": 0,
        "total": 0
      },
      "name": "src/app/example.js"
    }
  ],
  "repo_token": ""
}