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 #262

Open
lizhexia opened this issue Oct 15, 2014 · 60 comments

Comments

@lizhexia
Copy link

1.git clone https://github.com/lizhexia/ramlev.git
2.cd ramlev and npm install
3. 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 ?

@andrewrk
Copy link
Contributor

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

@ksmithut
Copy link

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.

@andrewrk
Copy link
Contributor

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.

@dougwilson
Copy link
Contributor

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.

@zaim
Copy link

zaim commented Jan 19, 2015

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

@tomek-he-him
Copy link

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

@danascheider
Copy link

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.

@davglass
Copy link
Collaborator

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

@danascheider
Copy link

Thank you, I found that out.

@egeland
Copy link

egeland commented Nov 20, 2015

@zaim - thanks, the underscore worked for me!

@carlitux
Copy link

carlitux commented Jan 1, 2016

Using babel-register getting:

No coverage information was collected, exit without writing coverage information

@yordis
Copy link

yordis commented Jan 2, 2016

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.

@nelsonic
Copy link

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

@carlitux
Copy link

@nelsonic no, I wasn't.

@nelsonic
Copy link

@carlitux sad times... 😢
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! 👍

@carlitux
Copy link

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

@ninjasort
Copy link

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

@carlitux
Copy link

carlitux commented Feb 6, 2016

@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

@ninjasort
Copy link

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

@ninjasort
Copy link

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

@nelsonic
Copy link

nelsonic commented Feb 6, 2016

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

@ninjasort
Copy link

@justinhelmer
Copy link

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

@creeperyang
Copy link

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

@carlitux
Copy link

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

@creeperyang
Copy link

@carlitux I just use istanbul@1.0.0-alpha.2.

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

@SamvelRaja
Copy link

SamvelRaja commented Feb 19, 2016

👍 for istanbul@1.0.0-alpha.2

@MrPeak
Copy link

MrPeak commented Feb 23, 2016

@zaim That works for me! Thx~ 👍

@MarcusSorealheis
Copy link

MarcusSorealheis commented Sep 27, 2016

istanbul cover _mocha --require setup.js -- --compilers jsx:babel-core/register --recursive test/* I also am using istanbul@1.1.0-alpha.1

works very well.

@gaboom
Copy link

gaboom commented Oct 31, 2016

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

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

@unstoo
Copy link

unstoo commented Jan 5, 2017

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 

@SystemParadox
Copy link

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 istanbul@1.0.0-alpha.2, 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/)

@rcjsuen
Copy link

rcjsuen commented Feb 5, 2017

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"

@PiotrBerebecki
Copy link

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"

@Grantlyk
Copy link

For anyone who is using ES6

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

@mfc3370
Copy link

mfc3370 commented Jul 4, 2017

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

@heisian
Copy link

heisian commented Aug 4, 2017

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',
});

@ArvoGuo
Copy link

ArvoGuo commented Dec 22, 2017

nice istanbul@1.1.0-alpha.1!

@sadafzohra19
Copy link

@zaim thanks Sir

@clancytom
Copy link

clancytom commented Apr 2, 2018

  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 ",
"istanbul": "^0.4.5",
node : v8.9.2

@iamdevlinph
Copy link

"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

@iamdevlinph
Copy link

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

@pranavavva
Copy link

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.

@mfc3370
Copy link

mfc3370 commented Sep 6, 2018

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

@pranavavva
Copy link

pranavavva commented Sep 6, 2018 via email

simeg added a commit to simeg/gulpfile-generator that referenced this issue Dec 15, 2018
@tang9716
Copy link

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

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