istanbuljs / nyc

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

Feature Request: Fail On Empty 🙏🏼 #1482

Open PepperAddict opened 2 years ago

PepperAddict commented 2 years ago

Link to bug demonstration repository

At first I thought it was a bug which is why I created a stackoverflow question: https://stackoverflow.com/questions/73115602/cypress-code-coverage-one-file-with-0-should-fail-test until I found an existing github issue: https://github.com/istanbuljs/nyc/issues/1166 that was ignored and closed which was exactly what we need. I was hoping to revive this topic and hopefully have it as a feature.

Expected Behavior

Empty files in code coverage should fail since it doesn't reach the test requirement. Since this isn't considered a bug, could it be a feature with an added flag/configuration that a user can add that way it will force users to create tests?

Observed Behavior

The code coverage result below is a success, but the file fakebox.tsx is empty so it shows 0. Since box.tsx was a success, it will pass the test anyway despite the problem with fakebox.tsx

-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |     100 |      100 |     100 |     100 |                                                     
 molecules/boxes   |     100 |      100 |     100 |     100 |                   
  Box.tsx          |     100 |      100 |     100 |     100 |                   
 molecules/fakebox |       0 |        0 |       0 |       0 |                   
  fakebox.tsx      |       0 |        0 |       0 |       0 |                   
-------------------|---------|----------|---------|---------|-------------------

Troubleshooting steps

Environment Information

# paste the output here

  System:
    OS: macOS 12.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 60.25 MB / 16.00 GB
  Binaries:
    Node: 12.20.2 - ~/.nvm/versions/node/v12.20.2/bin/node
    npm: 6.14.11 - ~/.nvm/versions/node/v12.20.2/bin/npm
  npmPackages:
    @babel/core: ^7.15.8 => 7.18.6 
    @babel/plugin-transform-runtime: ^7.15.8 => 7.18.6 
    @babel/preset-env: ^7.15.8 => 7.18.6 
    @babel/preset-react: ^7.14.5 => 7.18.6 
    @babel/preset-typescript: ^7.10.4 => 7.18.6 
    babel-loader: ^8.2.2 => 8.2.5 
    babel-plugin-istanbul: ^6.1.1 => 6.1.1 
    typescript: ^4.5.2 => 4.7.4

in short:

Could we get a new flag/config that fails the test if there are empty files that output 0? for ex: failOnEmpty = true (default false) or similar, please 🙏🏼 ? Thank you in advance!