Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

fix: coverage yields empty reports #246

Merged
merged 5 commits into from
Oct 12, 2017
Merged

fix: coverage yields empty reports #246

merged 5 commits into from
Oct 12, 2017

Conversation

mblarsen
Copy link
Collaborator

@mblarsen mblarsen commented Oct 3, 2017

Fix for #245

The coverage preprocessor was never added when enabling coverage. It was only added as reporter.


UPDATE: After submitting the first PR the code has gone in a different direction after reading hundreds of githubs issues, PRs, boilerplates, etc.

coverage should not be a preprocessor and also you don't have to add your src files to files it is enough to include the test files.

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 3, 2017

Although this fixes the issue there are some remaining issues:

  1. Everything in files will be covered.
  2. You'll need to add your source files to files as well. Not just the tests.
  3. The coverage is of the webpack'ed files. Not the source files. I'm wondering if this https://github.com/webpack-contrib/istanbul-instrumenter-loader should be used.

screen shot 2017-10-03 at 6 48 59 pm

For 1-2 I suggest explicitly telling what to cover:

   coverage: true,
   coverFiles: [ 'src/*.js' ],

And then use that to concat to files and use directly in preprocessors instead of reducing over files.

(this is a breaking change of course :/ )

These should probably be split out into new issues.

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 4, 2017

@egoist I'll examine this further. It shouldn't be necessary to specify the source files, so something else must be wrong.

Please ignore this PR for now :)

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 7, 2017

Maaaan, this took some time to get right. There are so many test/coverage/transpiler modules out there that are influx. This is not the time for coverage of es6 with tests written in es6 hehe.

But it works now:

screen shot 2017-10-07 at 8 44 23 pm

A key part of getting it to work was to use an old version of istanbul-instrumenter-loader as the never versions doesn't work with html and lcov reporters (only lcovonly reporter).

@egoist
Copy link
Owner

egoist commented Oct 7, 2017

does this work on .vue files?

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 7, 2017

Not sure, will test.

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 7, 2017

It does work, however it will includes other files as well -- used to transpile vue.

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 7, 2017

screen shot 2017-10-07 at 9 34 32 pm

Not ideal, will try to get rid of those.

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 7, 2017

I think I might need to do something like this vuejs/vue-loader#7 (comment) to get it working correctly with vue.

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 7, 2017

Also this may be relevant: webpack-contrib/istanbul-instrumenter-loader#73

@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 7, 2017

Btw, for context coverage: true doesn't work for anything prior to this PR. But I think we should get vue (and possible and others) to work also before merging anything.

@mblarsen mblarsen force-pushed the fix-245 branch 2 times, most recently from 0b71a8c to 2ef1ea6 Compare October 9, 2017 06:11
@mblarsen
Copy link
Collaborator Author

mblarsen commented Oct 9, 2017

@egoist I got code coverage working on both regular js and on vue. Also I sorted out the excess files included in the reports to that the coverage values are now accurate.

There is one part of the solution I'm not particular happy with and I was wondering if there are other ways to modify and existing loader than the way I am doing. (the mapping of rules part)

js:

screen shot 2017-10-09 at 1 42 59 pm

vue:

screen shot 2017-10-09 at 1 43 10 pm

@mblarsen mblarsen changed the title fix: coverage was never added as preprocessors. Fixes #245 fix: coverage yields empty reports. Oct 9, 2017
@mblarsen mblarsen changed the title fix: coverage yields empty reports. fix: coverage yields empty reports Oct 9, 2017
It is important to note that this is version 0.2.0 of the module.
Versions after that does not support the html and lcov reporters
(lcovonly is supported).
}
].concat(webpackConfig.module.rules)
/* for vue (assumes vue-loader) */
webpackConfig.module.rules = webpackConfig.module.rules
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually you can update webpack config in poi.extendWebpack('test', config => {}) using webpack-chain

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update this :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'm new to webpack-chain will check it out. It looks promising.

const options = r.use[vueLoaderPos].options
const instrumenterLoader = 'istanbul-instrumenter-loader?esModules=true'
options.preLoaders = (options.preLoaders || {})
options.preLoaders.js = typeof options.preLoaders.js === 'string' ?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it's preLoader for .vue file but postLoader for .js file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it should be pre for both. If you use post it will run the coverage after the babel-plugin-add-module-exports has run which adds something like this to the top:

screen shot 2017-10-10 at 1 51 11 pm

Do you want me to change both to pre (as they should be) or can you correct it when you add the webpack-chain stuff @egoist

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks I will webpack-chain-ify it later today

@egoist egoist merged commit 6309119 into egoist:master Oct 12, 2017
@mblarsen mblarsen deleted the fix-245 branch October 12, 2017 14:25
@mblarsen mblarsen restored the fix-245 branch October 17, 2017 16:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants