Istanbul: No coverage information was collected, exit without writing coverage information

Created on 15 Oct 2014  ·  60Comments  ·  Source: gotwarlost/istanbul

1.git clone https://github.com/lizhexia/ramlev.git
2.cd ramlev and npm install

  1. istanbul cover npm test
    error :No coverage information was collected, exit without writing coverage information
    what can i do for this question ,why can't work ?

Most helpful comment

If anyone is using mocha, use the "underscored" _mocha command instead of mocha. If you're using package.json run-scripts, simply do something like this:

{
  "scripts": {
    "test": "mocha",
    "test-cov": "istanbul cover _mocha"
  }
}

All 60 comments

same question. this error message does not help me figure out what to do.

I've been digging around into istanbul for the last hour or so because I've been having the same issue. It works for all of my repos except for one new project. I'm not positive, but I believe it might be because istanbul uses the require and module loading mechanisms of node to run code coverage. Because your tests are being tested like a cli, it doesn't use require, at least in the same process. Again, please someone correct me if I'm wrong or misunderstand the way istanbul works. I haven't looked at the entire codebase to know how all of the moving parts work.

The issue that I am having is different. At the top of my tests, I require 3 modules:

var expect     = require('expect.js');
var metalsmith = require('metalsmith');
var globMeta   = require('../');

globMeta is the module I want to actually test. When I start digging through all of the files registered through istanbul, I notice all of the expect.js stuff and the metalsmith stuff, but not my globMeta module. Oddly, to fix it, I just needed to move my globMeta module requiring up higher on the list of requires.

Although my issue only relates to yours by Error Message only, it would still be good to make this issue known to the maintainer.

watch out for forking. I resolved this problem by discovering that something was forking a child process to run node code and that's why it didn't get covered.

If anyway wants to know how to use Istanbul with forked tests, you can look at the "mysql" module, which runs every test in it's own fork, but correctly collects coverage anyway.

If anyone is using mocha, use the "underscored" _mocha command instead of mocha. If you're using package.json run-scripts, simply do something like this:

{
  "scripts": {
    "test": "mocha",
    "test-cov": "istanbul cover _mocha"
  }
}

I had the same message, but quite a different problem. I’m transpiling ES6 code to ES5 with _babel_. I want to run the tests in an ES5 environment, so I compile them into a directory called .es5 before testing.

It turns out that while istanbul cover .es5/test.js results in the same message as above, cd .es5 && istanbul cover test.js is OK.

Hope this helps someone :)

I'm getting the same message running Jasmine tests from the command line (not the Jasmine-Node package, but just plain old Jasmine, running under iojs). I have npm test wired to run jasmine. When I run

istanbul cover npm test
I get this same error message. When I just run
istanbul cover jasmine
it works fine. I wish I could suggest a solution but I haven't reached a resolution, so I really can't at this point. Hopefully what I've shared can help track down the problem, if indeed this is a problem and not expected behavior.

EDIT: I feel stupid for not realizing this before I wrote, but this code works perfectly:

npm test --coverage
Hopefully this can help someone else.

@danascheider Running istanbul cover npm test isn't the proper way to run it.

You should add "scripts": { "test": "istanbul cover jasmine" } in your package.json to get npm test to run the coverage.

Thank you, I found that out.

@zaim - thanks, the underscore worked for me!

Using babel-register getting:

No coverage information was collected, exit without writing coverage information

I am currently doing "test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/mocha" and doesn't work. When I used _mocha does work, but.

Why do I have to use _mocha? Answer #436 Basically _mocha is the real mocha executable. mocha is a wrapper for that executable.

@carlitux were you able to get istanbul working with babel ...?

@nelsonic no, I wasn't.

@carlitux sad times... :cry:
we are _experimenting_ with: https://github.com/ambitioninc/babel-istanbul
so far it looks quite _promising_ ...
see: https://travis-ci.org/dwyl/ampl/builds/103683244#L297
If you find an _alternative_ way of running ES6 code through istanbul (_standard version_) _please_ let us know! :+1:

@nelsonic thanks babel-istanbul is working for me... I hope both projects can merged soon

I'm getting the same No coverage information was collected, exit without writing coverage information for both istanbul and babel-istanbul

@cameronjroe I am using in this way.

./node_modules/.bin/babel-node node_modules/.bin/babel-istanbul cover node_modules/.bin/_mocha --report text --check-coverage -- --timeout 5000 -u tdd --recursive app/tests frontend/javascript/tests

Yeah, I actually found that out too. Thanks @carlitux

For some reason it's not running on travis-ci. Have you had this issue?

@cameronjroe please add a _link_ to the build on travis-ci where the coverage is not being collected so people can help you debug why its not working...

The answer here by @zaim and the answer here by @yordis identified the solution (or rather lack of understanding) that worked for me.

Thanks. I update istanbul to 1.x and solve the issue.

@creeperyang this use babel-node? what is the command to use istanbul instead of istanbul-babel...

@carlitux I just use [email protected].

command is like:

"test-cov": "node_modules/.bin/babel-node node_modules/.bin/istanbul cover --dir test/coverage test/run.js"

And my repo: https://github.com/creeperyang/ysprite

@zaim That works for me! Thx~ :+1:

+1 for [email protected] :+1:

Installing [email protected] worked for me too.

Thanks @creeperyang!

+1 [email protected]
Using cmd "cover": "babel-node node_modules/.bin/istanbul cover _mocha"
+1 @creeperyang

Thanks, everyone, for pointer to 1.0.0-alpha.2. Solved my "no coverage information" problem, too.

+1 for [email protected]

Another way to do it (without using babel-node) is to use Babel's require hook:

"coverage": "istanbul cover _mocha -- --require babel-register test"

+1 for [email protected]

This solved my problem.

+1 for [email protected]

Solved it. Thank you

Since the previous comment a new release has been added, which works for me as well:
[email protected]

Using it like so:
istanbul cover _mocha -- --compilers js:babel-register
(from "scripts" section in package.json)

👍 for [email protected]

Using it like this: istanbul cover _mocha -- public/**/*.test.js --compilers js:babel-register

It dint work for me
using [email protected]
running using command
"istanbul cover mocha -- --compilers js:babel-core/register --require ./client/test/testHelper.js --recursive ./client/test"
Runs the tests okay but then displays this message
No coverage information was collected, exit without writing coverage information
Anyone else on the same boat ?

@sahilaug
try to use _mocha instead of mocha.

Thanks @zlargon that worked. Had been struggling for hours ? Any explanation/reasoning ?

@sahilaug https://github.com/gotwarlost/istanbul/issues/44
This can help answer your question. 😀

istanbul cover _mocha --require setup.js -- --compilers jsx:babel-core/register --recursive test/* I also am using [email protected]

works very well.

After lots of trying it worked for me after upgrading istanbul to v1, in particular 1.1.0-alpha.1
Full configuration follows. Only depends on istanbul and babel-register (and mocha in my case, but I guess other test frameworks would work as well.) NOT using isparta nor babel-cli nor babel-node.

package.json

    scripts: {
`        "test": "istanbul cover node_modules/mocha/bin/_mocha --report html --report text -x \"**.spec.js\""
    },

test/mocha.conf

--reporter spec
--timeout 1000
--check-leaks
--compilers js:babel-register
--require babel-polyfill
--recursive
--sort
app/**/*.spec.js

If you are already using babel-core you can use babel-core/register as compiler instead of babel-register.

This one hasn't worked for me:

"scripts" : {
"test:single": "istanbul cover -x *.test.js _mocha -- -R spec src/index.test.js" }

This one did:

"scripts" : {
"test:single": "istanbul cover -x *.test.js ./node_modules/mocha/bin/_mocha -- -R spec src/index.test.js" }

Using "istanbul": "1.0.0-alpha.2".

It seems there's something wrong with /.bin/_mocha script. Unfortunately, it's cryptic for me, so I could be wrong. But I'll leave it here:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/../mocha/bin/_mocha" "$@"
  ret=$?
else 
  node  "$basedir/../mocha/bin/_mocha" "$@"
  ret=$?
fi
exit $ret 

Note that if you're using babel, this will happen if you use mocha --register js:babel-core/register (or if it's in test/mocha.opts). Solutions:

  • Upgrade to [email protected], although this seems to still have issues with incorrect coverage
  • Pre-compile your tests and run the compiled version
  • Use the new nyc package and babel-plugin-istanbul (see https://istanbul.js.org/docs/tutorials/es2015/)

The workaround from @yordis worked for me on Istanbul 0.4.5. Thanks!

I have Istanbul installed globally with -g.
"test-cov": "istanbul cover ./node_modules/mocha/bin/_mocha"

The coverage report is generated when I rename the directory with my test files from tests to something else, e.g. back-end-tests. I'm on "istanbul": "^0.4.5"

For anyone who is using ES6

"test:coverage": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/.bin/_mocha"

Moving my scripts inside "src" folder solved it for me.

Format working for me with Node 8.1.4:

# In terminal:
./node_modules/.bin/babel-istanbul cover ./node_modules/.bin/_mocha -- \
./bin/test.js -r babel-register -r babel-polyfill --slow 2000 -b -t 20000
// When used in my CLI dev tool:
require('child_process').fork('./node_modules/.bin/babel-istanbul', [
  'cover', './node_modules/.bin/_mocha', '--dir', `./coverage/${server}`,
  '--', './bin/test.js', '-r', 'babel-register', '-r', 'babel-polyfill',
  '--slow', '2000', '-b', `-t 20000`,
], {
  execPath: './node_modules/.bin/babel-node',
});

@zaim thanks Sir

  25 passing (3s)
No coverage information was collected, exit without writing coverage information
"coverage": "istanbul cover node_modules/mocha/bin/_mocha ./dist/test/testcase/*.test.js ",



md5-ca90781a66e5f7878b85ca46208efb19



"istanbul": "^0.4.5",
node : v8.9.2

"cover": "cross-env BABEL_ENV=commonjs istanbul cover ./node_modules/mocha/bin/_mocha -- --require babel-core/register --recursive ./src/**/*.spec.js",

No coverage information was collected, exit without writing coverage information

I use the full path of _mocha because of this SO answer. It wasn't working using _mocha directly.

This is the repo in question

I copied the cover script from here

Fixed my case with the following

package.json

"scripts": {
  "cover": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha src/**/*.spec.js",
},
"nyc": {
  "register": "babel-register",
  "include": [
    "src/**/*.js"
  ],
  "require": [
    "babel-register"
  ],
  "reporter": [
    "lcov",
    "text"
  ],
  "sourceMap": false,
  "instrument": false,
  "all": true
},

.babelrc

{
  "presets": ["env"],
  "plugins": ["babel-plugin-add-module-exports"],
  "env": {
    "test": {
      "plugins": [
        "istanbul"
      ]
    }
  }
}

doesn't work on windows. running istanbul cover ./node_modules/mocha/bin/_mocha and istanbul cover ./node_modules/mocha/bin/mocha both successfully _test_ my code, but on exit, it still says No coverage information was collected, exit without writing coverage information
for example.

$ istanbul cover ./node_modules/mocha/bin/mocha


  Application launch
    √ opens one initial window (130ms)
    √ has correct title

  DOM Structure
    √ has two <link>s in <head> (40ms)
    √ first <link> is stylesheet (69ms)
    √ second <link> is stylesheet (52ms)
    √ has 7 <select> or <input> in total (56ms)


  6 passing (12s)

No coverage information was collected, exit without writing coverage information

I know istanbul doesn't parse .cmd files, but mocha doesn't have a .js file in its bin/ unless i messed something.
Anyone know what I'm doing wrong? A quick reply would be greatly appreciated.

@20avva install the nyc module, then use it with mocha, to get the coverage.
These are how the files look on my npm scripts:

"test": "mocha $(find test -name '*.spec.js')",
"test-with-coverage": "nyc mocha $(find test -name '*.spec.js')",

Hope that helps.

Thanks. I’ll give it shot.

Respectfully,
Pranav Avva

On Sep 6, 2018, at 02:09, mfc3370 notifications@github.com wrote:

@20avva install the nyc module, then use it with mocha, to get the coverage.
These are how the files look on my npm scripts:

"test": "mocha $(find test -name '.spec.js')",
"coverage-with-coverage": "nyc mocha $(find test -name '
.spec.js')",

Hope that helps.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

"cover": "istanbul cover _mocha test/mocha.js"
仍然报错且无输出
去掉_mocha输出后报错
为什么呢

Was this page helpful?
0 / 5 - 0 ratings

Related issues

luisonthekeyboard picture luisonthekeyboard  ·  16Comments

dcrockwell picture dcrockwell  ·  37Comments

Raynos picture Raynos  ·  27Comments

briancullinan picture briancullinan  ·  22Comments

gbahamondezc picture gbahamondezc  ·  24Comments