Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combined coverage for Branches does not add up to 100% #1508

Open
1 task done
samhatoum opened this issue Feb 4, 2023 · 4 comments
Open
1 task done

Combined coverage for Branches does not add up to 100% #1508

samhatoum opened this issue Feb 4, 2023 · 4 comments

Comments

@samhatoum
Copy link

samhatoum commented Feb 4, 2023

EDIT: this issue as partly fixed by using babel instead of v8 in Jest, however the branches still do not add up to 100% despite the single report from Jest does show 100% branch coverage. More in the thread.

Link to bug demonstration repository

https://github.com/samhatoum/monorepro/tree/nyc (note the nyc branch`)

Expected Behavior

Combined coverage from two test runs should add up 100% when one of the input coverage reports has 100% coverage

Observed Behavior

Combined coverage is reduced when the second test run contains less than 100% test coverage

Here's the report from Jest
jest 100-100-100-100

Here's the report from Cucumber:
cucumber 60-50-40-55

Here's the combined report:
combined 88-83-66-100

.nycrc.json

{
  "require": ["tsconfig-paths/register"],
  "extends": "./nyc-config.js",
  "cwd": ".",
  "all": true,
  "reporter": [
    "lcovonly",
    "json",
    "html"
  ],
  "temp-dir" : "coverage/.nyc_output",
  "include": ["**/*.{ts,tsx}"],
  "exclude": [
    "jest.config.ts",
    "specs/*"
  ]
}

package.json scripts that produce the above

    "test": "yarn ensure:dirs && yarn test:jest && yarn test:cucumber && yarn coverage:combine",
    "test:jest": "jest --coverage",
    "test:cucumber": "nyc --report-dir=./coverage/cucumber cucumber-js",
    "ensure:dirs" : "(rm -rf coverage || true) && (mkdir -p coverage/reports || true)",
    "ensure:dir:nyc" : "(rm -rf ./coverage/.nyc_output || true) && mkdir ./coverage/.nyc_output",
    "coverage:copy:reports:cucumber": "cp coverage/cucumber/coverage-final.json coverage/reports/from-cucumber.json",
    "coverage:copy:reports:jest": "cp coverage/jest/coverage-final.json coverage/reports/from-jest.json",
    "coverage:copy:reports": "yarn coverage:copy:reports:jest && yarn coverage:copy:reports:cucumber",
    "coverage:combine:reports": "yarn ensure:dir:nyc && nyc merge coverage/reports && mv coverage.json coverage/.nyc_output/out.json",
    "coverage:finalize:combined-report": "nyc report --reporter html --reporter text-summary  --report-dir coverage/combined-coverage --cwd .",
    "coverage:combine": "yarn coverage:copy:reports && yarn coverage:combine:reports && yarn coverage:finalize:combined-report"

Troubleshooting steps

  • still occurring when I put cache: false in my nyc config

Environment Information

  System:
    OS: macOS 13.2
    CPU: (12) arm64 Apple M2 Max
    Memory: 17.21 GB / 96.00 GB
  Binaries:
    Node: 18.8.0 - ~/.nvm/versions/node/v18.8.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.8.0/bin/yarn
    npm: 9.1.2 - ~/.nvm/versions/node/v18.8.0/bin/npm
  npmPackages:
    nyc: ^15.1.0 => 15.1.0 
    ts-node: ^10.9.1 => 10.9.1 
    typescript: ~4.9.4 => 4.9.4 
@AriPerkkio
Copy link

You can't mix Istanbul instrumented coverage with V8 coverage. Use the same instrumenter for both test setups.

E.g. change 'babel' here to use istanbul with Jest: https://github.com/samhatoum/monorepro/blob/c6203edacde44b93eb5a48cf09feaea9b408ade0/jest.config.ts#L6

@samhatoum
Copy link
Author

samhatoum commented Feb 17, 2023

Thank you, that's definitely improved it, but the branches now show as 50% combined coverage.
improved

I've updated the repo

@samhatoum samhatoum changed the title Combined coverage does not add up to 100% Combined coverage for Branches does not add up to 100% Feb 24, 2023
@varunrajasekhar
Copy link

@samhatoum - were you able to resolve it ?
I am having the same issue with nyc 15.1.0 , Node 18.17.0 and mocha 10.2.0 version

#1540

@samhatoum
Copy link
Author

No, just learned to live with it and reduce the thresholds. I'd love to see it fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants