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

No coverage information was collected, exit without writing coverage information #496

Closed
niftylettuce opened this issue Nov 28, 2015 · 29 comments

Comments

@niftylettuce
Copy link

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.

@ramirezj
Copy link

Likewise, though there appears to be a package on NPM that handles this it would be useful to understand the situation within Istanbul first

@JakeSidSmith
Copy link

👍

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)?

@gotwarlost
Copy link
Owner

Is there a simple project on github on which I can run some experiments? If not could you create one?

Thanks.

@JakeSidSmith
Copy link

I'll whip one up quickly. :)

@JakeSidSmith
Copy link

Here you go: https://github.com/JakeSidSmith/istanbul-no-coverage

@gotwarlost
Copy link
Owner

JakeSidSmith/istanbul-no-coverage#1

@JakeSidSmith
Copy link

Awesome. I'll give it a go on our project when I have a chance. :)

@JakeSidSmith
Copy link

Just tested it on our project. Works perfectly, thanks. :)

@chazzlabs
Copy link

@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",

@kmudrick
Copy link

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 istanbuljs/sample-babel-node#1

@tswaters
Copy link

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.

@connorwang
Copy link

@tswaters
Copy link

tswaters commented Jan 6, 2016

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.)

@gotwarlost
Copy link
Owner

I pushed a fix for the relative paths problem that seems similar to #512 - could you please check if the situation has improved now?

@JakeSidSmith
Copy link

@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. :)

gpbl added a commit to gpbl/react-day-picker that referenced this issue Jan 26, 2016
@g-patel
Copy link

g-patel commented Jan 27, 2016

@gotwarlost, your fix in JakeSidSmith/istanbul-no-coverage#1 uses istanbul@1.0.0-alpha. 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?

@gotwarlost
Copy link
Owner

@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

@g-patel
Copy link

g-patel commented Jan 27, 2016

@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 JakeSidSmith/istanbul-no-coverage#1?

@mrwithersea
Copy link

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

@dahrens
Copy link

dahrens commented Feb 23, 2016

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.

gpbl added a commit to shoutit/shoutit-web that referenced this issue Mar 15, 2016
@zanuka
Copy link

zanuka commented Mar 25, 2016

using "istanbul": "^1.0.0-alpha" worked for me.

@witwit
Copy link

witwit commented Apr 19, 2016

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

@ericmdantas
Copy link

ericmdantas commented Apr 27, 2016

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"

@g-patel
Copy link

g-patel commented Jun 17, 2016

@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

@niftylettuce
Copy link
Author

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!

@rowlandekemezie
Copy link

rowlandekemezie commented Jul 30, 2016

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.

@dilipkumar2k6
Copy link

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"]
}

@sdtsui
Copy link

sdtsui commented Oct 20, 2016

@tswaters Your comment worked for me. Thanks!

@oshalygin
Copy link

@tswaters gold, thanks man that worked like a charm.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests