istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.61k stars 360 forks source link

ERROR: Coverage for lines (0%) does not meet global threshold (90%) #1516

Open ghsouza89 opened 1 year ago

ghsouza89 commented 1 year ago

Link to bug demonstration repository

sorry but i'm not able to share the repo because is a security policy from the company.

Expected Behavior

In my understanding i should see the coverage applied after follow the documentation and use nyc to instrument my application.

Observed Behavior

However i'm facing an error message and 0 coverage in the files that i want to be coverage:

ERROR: Coverage for lines (0%) does not meet global threshold (90%)

image

Troubleshooting steps

Environment Information

"nyc": "^15.1.0" doc reference: https://github.com/cypress-io/code-coverage#instrument-your-application

paste the output here

Melchyore commented 1 year ago

I have the same problem using v15.1.0.

Beakerboy commented 1 year ago

My repository is https://github.com/Beakerboy/Threejs-Geometries/tree/coverage

If I install nyc 15.1.0 with qunit 2.19.4, the unit tests run, but the coverage report fails to list any files. If I add --all, the coverage report does see all my files, but shows that no lines are covered.

nyc 15.0.1 gives me the error:

require() of ES Module /home/runner/work/Threejs-Geometries/Threejs-Geometries/src/PyramidGeometry.js not supported.
Instead change the require of PyramidGeometry.js in null to a dynamic import() which is available in all CommonJS modules.

My code does not have any require() statements. I saw a similar bug report that was attributed to and older version of babel. My GitHub repo is using @babel/generator@7.21.5

In my case, it’s possible I’m just doing something completely wrong that the install and usage manual assumes I would know better than to do. However, my project is not very large nor complex; just three classes.

Beakerboy commented 1 year ago

For me, I was able to successfully replace nyc with bcoe/c8.

kreamyu commented 1 year ago

@Beakerboy Hello, I met the same problem as you, I used nyc to test a project with Angular 11, only some branches coverage is 100, all lines coverage is 0. I also used c8, but all the coverage is 0, how did you achieve it?

Beakerboy commented 1 year ago

I just did a drop-in replacement. I called c8 quint instead of `nyc quint

my package.json includes this:

 "scripts": {
    "lint": "eslint .",
    "test": "c8 qunit"
  },
  "c8": {
    "all": true,
    "reporter": [
      "lcov",
      "text-summary"
    ]
  }

and my workflow includes:

    - name: Test
      run: npm test

https://github.com/Beakerboy/Threejs-Geometries/tree/main

VendenIX commented 1 year ago

I had the same problem, I found a solution, you can see it here: https://stackoverflow.com/questions/76588140/error-coverage-for-lines-0-does-not-meet-global-threshold-90-cypress