-
Notifications
You must be signed in to change notification settings - Fork 75
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
Use with code coverage / Istanbul? #19
Comments
To be honest, didn't tried code coverage with mocha-webpack yet... Maybe it's just enough to apply a loader for code coverage (see istanbul-instrumenter-loader). |
+1 |
I got this working! I used In
|
I needed to include FYI, the |
Since we're talking about coverage, I do have a question. At the moment, it only shows coverage for the components that are referenced in the test file, so the coverage results gives a wrong view when looking at the complete codebase. I guess it could be done by passing I also tried to hack in another approach that was more in line the karma-webpack setup I use in other projects, which is to create a second context for the source files. In the
And adding another contextReplacementPlugin in
I guess sourcePath could be added as an extra CLI option? How do you feel about these approaches? Is it worth starting a PR for this? |
This is what I use (typescript + webpack + react + mocha-webpack) :
webpack config:
|
@ntdb thanks that worked for me! |
@serut It worked for me by testing it on the commandline. |
I'm still using istanbul-instrumenter-loader, basically it works, but that's not so great, I write ES6 code and I get ES5 code coverage. I tryed to use https://github.com/istanbuljs/babel-plugin-istanbul with no success. EDITED: See 6 comments below my working configuration with babel-plugin-istanbul Here is my setup:
And the command I execute: 🐐 |
Don't know if this is related, but webpack had an issue with sourcemaps parsing of babel (webpack/source-list-map#3). You can either make sure that all of your dependencies are using |
I have the very same problem. Using webpack 1.14 and mocha-webpack 0.7.0 all I see is coverage for my webpack config. Coverage runs on nyc and babel-plugin-istanbul. |
I tried code coverage today with the latest master and everything works fine for me with just I'll write some docs for this setup that I used in my test repo: mocha-webpack-example. If someone wants to try that out, the repo relies on a linked/latest version of mocha-webpack. @serut |
Jan, that repo was a huge help. I managed to set everything up. Strange enough it worked with the instrumenter and not with the babel-plugin-istanbul even though the latter has much more traction on npm. Thanks for the quick help! |
Babel-plugin-istanbul works also for me. I used that before I included code coverage for typescript. See this commit zinserjan/mocha-webpack-example@f1af8be. |
@zinserjan This worked for me, thank you for the example commit!! |
Ok it works really great with
Finally, my run command in the
To sum up, the only difference with my previous test is |
I've managed to get this to work
This is very similar to @zinserjan example |
I tried @ntdb 's example, @zinserjan 's example, and @Izhaki 's and all result in 0% coverage. It's running, just not finding my files for some reason. |
@Izhaki You rock, thanks, but I figured it out. I basically uninstalled everything, and used: Just mocha, no mocha-webpack, or any of it's ilk. package.json scripts looks like this: "test": "mocha --compilers js:babel-core/register --require babel-polyfill src/**/*.test.js",
"coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text mocha --compilers js:babel-core/register --require babel-polyfill 'src/**/*.test.js'", Made sure .babelrc had the env: "env": {
"test": {
"plugins": [ "istanbul" ]
}
} Nothing required for the webpack like all the 20 billion sites say, but here it is all the same: module.exports = {
entry: ['babel-polyfill', './src/index.js'],
devtool: "inline-source-map",
output: {
filename: 'bundle.js'
}
}; I should point out, too, that this is a front-end JavaScript project using Pixi, but not all my tests deal with DOM and whatnot, so I was afraid I'd have to whip out the karma, but so far, no need. The |
Well. I haven't quite delve into this, but... mocha-webpack is a webpack plugin and it works on files within the webpack 'file system', which are not written to disk. Any coverage tool, unless a webpack plugin as well, should not marry well with any other webpack plugin. This is why you need There's more to say, but that's the gist of it. |
So should I change my setup to use mocha-webpack again, or...? |
@JesterXL On the contrary - stick to |
here's how we got it working (
(note the
we use and then from the cli call
|
I am trying to get code coverage with the following command
But that only covers my webpack config files! Because
coverage/coverage.json
only says{".../webpack.config.js":{...
(I copied this straight from https://github.com/nickmerwin/node-coveralls#istanbul and replaced
mocha
withmocha-webpack
.)The text was updated successfully, but these errors were encountered: