istanbuljs / nyc

the Istanbul command line interface

Home Page:https://istanbul.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coverage % alternates from one run to another

samblackmore opened this issue · comments

Link to bug demonstration repository

https://github.com/samblackmore/nyc-coverage-repro

Expected Behavior

The coverage report should be the same every time.

Observed Behavior

The coverage report alternates between Run A and Run B.

Run A:

----------------|----------|----------|----------|----------|-------------------|
File            |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------------|----------|----------|----------|----------|-------------------|
All files       |    48.48 |    48.28 |       25 |    57.69 |                   |
 lib            |    43.33 |    48.28 |    14.29 |    52.17 |                   |
  exports.ts    |      100 |      100 |      100 |      100 |                   |
  index.ts      |    34.62 |    48.28 |    14.29 |    42.11 |... 16,17,18,19,25 |
 tests          |      100 |      100 |      100 |      100 |                   |
  index.spec.ts |      100 |      100 |      100 |      100 |                   |
----------------|----------|----------|----------|----------|-------------------|

Run B:

----------------|----------|----------|----------|----------|-------------------|
File            |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------------|----------|----------|----------|----------|-------------------|
All files       |       44 |    47.62 |       20 |       55 |                   |
 lib            |    36.36 |    47.62 |        0 |    47.06 |                   |
  exports.ts    |      100 |      100 |      100 |      100 |                   |
  index.ts      |    22.22 |    47.62 |        0 |    30.77 |... 10,14,15,16,19 |
 tests          |      100 |      100 |      100 |      100 |                   |
  index.spec.ts |      100 |      100 |      100 |      100 |                   |
----------------|----------|----------|----------|----------|-------------------|

Troubleshooting steps

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

Observations

The following line is the culprit:

import MyDefaultValue, { foo } from './exports'

If I only use named exports or default exports in a single import statement, the coverage is consistent. However, it should be valid to use both named and default exports. From the Mozilla docs:

Every module can have two different types of export, named export and default export. You can have multiple named exports per module but only one default export.

Environment Information

  System:
    OS: macOS 11.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 7.06 GB / 32.00 GB
  Binaries:
    Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.0/bin/npm
  npmPackages:
    babel-core: ^6.26.3 => 6.26.3 
    babel-loader: ^7.1.5 => 7.1.5 
    babel-preset-env: ^1.7.0 => 1.7.0 
    babel-preset-react: ^6.24.1 => 6.24.1 
    nyc: ^13.3.0 => 13.3.0 
    ts-node: ^10.8.0 => 10.8.0 
    typescript: ^4.1.2 => 4.1.2