question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nyc --all option reporting wrong coverage results if all files are instrumented

See original GitHub issue

Expected Behavior

nyc should show correct coverage results of all instrumented files with --all option.

For example, if i have a.js and b.js in my application, unit tests only load a.js the total coverage could show as some percentage based on functionalities tested. If any of those files remain uncovered they will be factored into the report with a default of 0% coverage.

Observed Behavior

This was the result i am getting with all option enabled, shows no coverage results for any files even it failed for the files touched by my test suite shown below:

coverage_withall

If i disabled the --all option, it shows the coverage report for the files touched by test suite as shown below:

coverage_withoutall

Troubleshooting steps

  • still occurring when I put cache: false in my nyc config
{
  cache: false,
  all: true,
  "exclude": ["./coverage/**", "./dist/**", "**/*.spec.ts"]
}

Environment Information

“istanbul-instrumenter-loader”: “^3.0.1”, “nyc”: “^15.1.0”,

i am using cypress test runner and istanbul-instrumenter-loader to instrument the source code with this configuration in webpack:

 {
    test: /\.(js|ts)$/,
    loader: 'istanbul-instrumenter-loader',
    options: { esModules: true },
    enforce: 'post',
    include: require('path').join(__dirname, '..', 'src'),
    exclude: [
    /\.(e2e|spec)\.ts$/,
    /node_modules/,
    /(ngfactory|ngstyle)\.js/,
    ]
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
coreyfarrellcommented, Dec 7, 2020

I’m sorry I don’t use webpack so I can’t make direct recommendations. If it’s just a matter of getting the code instrumented then I assume webpack has a way to run babel 7, in that case the latest babel-plugin-istanbul is the best way to get coverage counters into your code.

0reactions
kishokcommented, Jun 30, 2021

hi @toaditoad I didn’t check that due to some reasons but you can try explore why the nyc output json have no source instrumentation code parts if we used --all option by deep dive in their source code. This is required if you want full code coverage report. I think community is not very much active currently !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect code coverage using nyc with Jest Based E2E Test ...
I am trying to generate code coverage for the single e2e test case. Here is what I did to achieve this. Instrumented files...
Read more >
nyc/README.md - UNPKG
When a file is `require()`'d, nyc creates and returns an instrumented version of the source, rather than the original. 240, Only source files...
Read more >
istanbuljs/nyc - Gitter
(now all of them are have a 100% coverage by default) ... there anyway I can get around test-exclude disallowing instrumentation of files...
Read more >
Test runner Addon | Storybook: Frontend workshop for UI ...
Storybook test runner turns all of your stories into executable tests. ... 1 - Instrument the code ... Merging test coverage results in...
Read more >
@cypress/code-coverage - npm Package Health Analysis | Snyk
Note: if you have all: true NYC option set, this plugin will check the produced .nyc_output/out.json before generating the final report. If the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found