I can't get any coverage output regardless if I do --report lcov --report html or leave it blank.
This seems to be a bug with latest versions... it used to work fine.
I'm using ES6/mocha and having mocha call babel-core/register.
I've tried every combination of babel-node, ./node_modules/.bin/xyz etc - still no coverage - I've tried lots of options, even --hook-run-in-context which I have no idea what it does, because there's not much documentation for it, or any features. Even the readme of this repo doesn't even talk about available options to pass to --report.
Likewise, though there appears to be a package on NPM that handles this it would be useful to understand the situation within Istanbul first
:+1:
I've just started using mocha and decided to give istanbul a try for our coverage.
I'm having this exact issue, but after trying every possible solution I've read, I'm still getting "No coverage information was collected, exit without writing coverage information". Glad I'm not the only one.
Have this in my package.json:
"scripts": {
"test": "istanbul cover node_modules/mocha/bin/_mocha -- --compilers js:babel-core/register --require scripts/test-helper.js --recursive 'src/js/__tests__/**/*.test.js'"
},
Our .babelrc has some presets in it for ES6 & React / JSX.
{
"presets": [
"es2015",
"react"
]
}
Not using an .istanbul.yml as I'd already tried a ton of different configurations & nothing seems to work.
This the same setup you guys are running (roughly)?
Is there a simple project on github on which I can run some experiments? If not could you create one?
Thanks.
I'll whip one up quickly. :)
Here you go: https://github.com/JakeSidSmith/istanbul-no-coverage
Awesome. I'll give it a go on our project when I have a chance. :)
Just tested it on our project. Works perfectly, thanks. :)
@gotwarlost This fix works in my case as well, but I need to run Sonar against the resulting lcov file. Using the fix you made in JakeSidSmith/istanbul-no-coverage#1 the file paths in the lcov file are no longer absolute and therefore cannot be analyzed by Sonar. I'm seeing some mixed things depending on Node version. Keep in mind I'm also using ES2015 and babel-register in my project.
From package.json in Node 0.12.2
Generates lcov file with relative file paths which cannot be analyzed by Sonar:
"coverage": "babel-node ./node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha -- --recursive"
Fails because no compiler is supplied to Mocha:
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --recursive",
From package.json in Node 5.2.0
Generates lcov file with relative file paths which cannot be analyzed by Sonar (same as above):
"coverage": "babel-node ./node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha -- --recursive"
Generates lcov file with absolute file paths which can be analyzed by Sonar:
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --recursive",
FWIW I am seeing issues even in the sample-babel-node project - seems to be flattening the paths of the source in the coverage output. Not sure if that is related to this issue or what. I opened https://github.com/istanbuljs/sample-babel-node/issues/1
I just encountered this issue "No coverage information was collected..." The specific thing that was breaking it for me was --compilers js:babel-register in mocha.opts (or passed via args).
To clarify -- with babel-register present as require/compiler option, no coverage information will be collected, even if wrapping the script in babel-node. The only way to get it working _and_ have coverage is to not include babel-register and to wrap the istanbul cover call with babel-node.
For what it's worth, not being dependent on babel-node and getting the babel-register working would be great for build tools... I'm having a heck of a time getting this to work under grunt-mocha-istanbul -- either no coverage information is collected or the entire thing blows up without a transpiler.
@tswaters follow this tutorial https://onsen.io/blog/mocha-chaijs-unit-test-coverage-es6/
I ended up not using --compiler in mocha.opts, including npm scripts for test (mocha with compiler) and coverage (babel-node with istanbul without compiler) and running each through grunt-shell. This works fine.
Still, right now the 1.x branch of istanbul does not work with compiler option - right now it is not able to collect any coverage information. (At least with babel-register, I haven't tried any others.)
I pushed a fix for the relative paths problem that seems similar to #512 - could you please check if the situation has improved now?
@gotwarlost I'd run into an issue with coverage being collected for files with similar names e.g. actions/ui.js and reducers/ui.js would share the same coverage, but after clearing istanbul & reinstalling (with the latest istanbul-lib-source-maps) this seems to be fixed. :)
@gotwarlost, your fix in https://github.com/JakeSidSmith/istanbul-no-coverage/pull/1 uses [email protected]. Does this mean this won't work with stable version of istanbul as of now? I am referring to the issue of "creating coverage when using js:babel-register compiler with mocha". What is ETA on the fix being available in stable release?
@g-patel - correct. I'm working on making it stable; needs additional tests and interface stability of the source maps module. It is pretty usable as is - the alpha tag is to protect my ability to make changes to the public API without a new major version. If you are using the command line, there will likely be no impact.
See also: https://github.com/istanbuljs/sample-mocha-compilers for a different way of doing things when mocha and babel are involved
@gotwarlost got it. Thanks for reply. One more thing. That famous ES6 coverage article mentions about using isparta for istanbul to understand ES6 code. Is it really needed after your fix https://github.com/JakeSidSmith/istanbul-no-coverage/pull/1?
For anyone this might help this works for us
istanbul cover ./node_modules/.bin/_mocha -- 'test/unit/**/*.js' --require babel-core/register --require test/support/global
And in our .istanbul.yml file:
instrumentation:
root: src
extensions:
- .jsx
- .js
with a structure like that:
.
+-- .istanbul.yml
+-- .babelrc
+-- package.json
+-- src
| +-- foo.es6
| +-- bar.es6
+-- test
| +-- foo.test.es6
| +-- bar.test.es6
and .istanbul.yml like this:
instrumentation:
root: src
extensions:
- .es6
using the following packages with nodejs 5.5.0:
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"istanbul": "^1.0.0-alpha",
"mocha": "^2.4.5"
},
i finally ended up with this _working_ command
./node_modules/.bin/babel-node ./node_modules/istanbul/lib/cli.js cover ./node_modules/.bin/_mocha -- 'test/**/*.es6' --require test/lib/bootstrap
@all thanks for the useful information out of this issue.
using "istanbul": "^1.0.0-alpha" worked for me.
still fails for me with the error:
Error: proxies not supported on this platform. On v8/node/iojs, make sure to pass the --harmony_proxies flag
using:
babel-node node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha -- --recursive --require test/setup.js
with istanbul ^1.0.0-alpha, also tried babel-istanbul
Istanbul 1.0, even though in alpha, did the trick for me.
Here's my config (for travis):
"babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/.bin/_mocha test/ --report lcovonly -- --recursive -R min --check-leaks --require babel-core/register && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
@gotwarlost Is the version 1.x moving out of alpha soon? The latest release for v1.x I see it the v1.0.0-alpha.2
It is now working with istanbul@^1.1.0-alpha.1. See my setup here https://github.com/niftylettuce/koa-ratelimit-promises and my code coverage report here https://codecov.io/gh/niftylettuce/koa-ratelimit-promises. Thanks!
Nice one @niftylettuce. I don't think you need all the node_modules/.bin/_mocha. The executables are already available for you to use. E.g
"istanbul cover _mocha -- --compilers js:babel-core/register --recursive 'src/**/*.test.js'"
is all you need with ^1.0.0-alpha.
Following worked for me with es6, react, mocha, enzyme and babel. It tests and generate reports.
"test": "babel-node ./node_modules/.bin/babel-istanbul cover _mocha -- 'test/**/*.test.@(js|jsx)' --compilers js:babel-register,css:test/unit/ignore-import",
ignore-import.js
// Prevent mocha from interpreting CSS @import files
function noop() {
return null;
}
require.extensions['.css'] = noop;
require.extensions['.scss'] = noop;
.bablerc
/*This file is only being used to run the unit test cases*/
{
"presets": ["react", "es2015", "stage-0"],
"plugins": [ "transform-decorators-legacy"]
}
.istanbul.yml
/*This file is only being used to run the unit test cases*/
{
"presets": ["react", "es2015", "stage-0"],
"plugins": [ "transform-decorators-legacy"]
}
@tswaters Your comment worked for me. Thanks!
@tswaters gold, thanks man that worked like a charm.
Most helpful comment
using "istanbul": "^1.0.0-alpha" worked for me.