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

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

Open
1 task done
kishok opened this issue Dec 7, 2020 · 8 comments
Open
1 task done

Comments

@kishok
Copy link

kishok commented Dec 7, 2020

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/,
    ]
}
@coreyfarrell
Copy link
Member

Neither istanbul-instrument-loader nor cypress are part of the istanbul organization. I'm not sure what is going on with these third party programs. Note that istanbul-instrument-loader uses a very old version of istanbul-lib-instrument so I'm not able to support this.

@kishok
Copy link
Author

kishok commented Dec 7, 2020

@coreyfarrell thanks for your valuable input. Could you please recommend which loader I can use in the webpack and support Istanbul libraries upto date ?

@coreyfarrell
Copy link
Member

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.

@kishok
Copy link
Author

kishok commented Dec 7, 2020

Ok @coreyfarrell . I will try this approach and see how it works with webpack builder and cypress test runner. And I will share my results 🙂

@kishok
Copy link
Author

kishok commented Dec 10, 2020

hi @coreyfarrell , i tried what you suggested to instrument the source code using babel-plugin-istanbul and if i specify all in the .nycrc, it shows all included files, but still does not detect the coverage. Here are the results

1)nyc with --all option

coverage_all

  1. nyc without --all option

coverage_withoutall

i need help to figure out this issue, if anything i have missed in configuration / code part. Here is an example repository https://github.com/kishok/ticket-coupon

@kishok
Copy link
Author

kishok commented Dec 22, 2020

hi @coreyfarrell, any suggestions please on the above query. How to solve this issue?

@toaditoad
Copy link

HI @kishok , were you able to solve this? I run into the same issue with a similar setup: https://github.com/toaditoad/code-coverage-mwe

@kishok
Copy link
Author

kishok commented 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 !

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