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

`require all src files` in unit/index.js useless? #928

Closed
njleonzhang opened this Issue Sep 18, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@njleonzhang
Copy link

njleonzhang commented Sep 18, 2017

Hi team,

Does the following code really useful? I remove the code from my project, but nothing change, it seems not impact the code coverage as the comments stated.

// require all src files except main.js for coverage.
// you can also change this to match only the subset of files that
// you want coverage for.
const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
srcContext.keys().forEach(srcContext){{#if_eq lintConfig "airbnb"}};{{/if_eq}}

According to karma-webpack doc, I can not find the purpose of these code too. If they are useful would you please give some explanation?

@LinusBorg

This comment has been minimized.

Copy link
Contributor

LinusBorg commented Sep 25, 2017

If you reference all source files from your tests anyway, then this has indeed no effect.

If however you tests leave out some source files, then this code would make sure they are still required and therefore taken into account when calculating coverage.

If that doesn't work as expected for you, maybe there's a bug?

@njleonzhang

This comment has been minimized.

Copy link
Author

njleonzhang commented Sep 25, 2017

@LinusBorg Tnx for explanation. I understand now. No bug exists.
In my project, I split template code to a independent pug file (for some reason). when run release/dev, no error occurs. But if I run npm run test, the pug file is loaded by above code, which need a pug-loader, error occurs. So I start to look into this test/index.js, and thinking why we need these lines. Now you provide me a explanation, I understand. tnx again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment