istanbul icon indicating copy to clipboard operation
istanbul copied to clipboard

No coverage information was collected, exit without writing coverage information

Open lizhexia opened this issue 9 years ago • 60 comments

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 ?

lizhexia avatar Oct 15 '14 10:10 lizhexia

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

andrewrk avatar Oct 22 '14 22:10 andrewrk

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.

ksmithut avatar Oct 29 '14 14:10 ksmithut

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.

andrewrk avatar Oct 29 '14 16:10 andrewrk

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.

dougwilson avatar Jan 10 '15 04:01 dougwilson

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

zaim avatar Jan 19 '15 17:01 zaim

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

tomek-he-him avatar May 05 '15 06:05 tomek-he-him

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 avatar Jun 30 '15 17:06 danascheider

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

davglass avatar Jun 30 '15 18:06 davglass

Thank you, I found that out.

danascheider avatar Jun 30 '15 19:06 danascheider

@zaim - thanks, the underscore worked for me!

egeland avatar Nov 20 '15 03:11 egeland

Using babel-register getting:

No coverage information was collected, exit without writing coverage information

carlitux avatar Jan 01 '16 03:01 carlitux

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.

yordis avatar Jan 02 '16 03:01 yordis

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

nelsonic avatar Jan 20 '16 17:01 nelsonic

@nelsonic no, I wasn't.

carlitux avatar Jan 20 '16 19:01 carlitux

@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 avatar Jan 20 '16 19:01 nelsonic

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

carlitux avatar Jan 20 '16 21:01 carlitux

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

ninjasort avatar Feb 06 '16 02:02 ninjasort

@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

carlitux avatar Feb 06 '16 17:02 carlitux

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

ninjasort avatar Feb 06 '16 19:02 ninjasort

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

ninjasort avatar Feb 06 '16 21:02 ninjasort

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

nelsonic avatar Feb 06 '16 21:02 nelsonic

https://travis-ci.org/cameronjroe/founders-names#L138

ninjasort avatar Feb 06 '16 21:02 ninjasort

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

justinhelmer avatar Feb 09 '16 19:02 justinhelmer

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

creeperyang avatar Feb 17 '16 05:02 creeperyang

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

carlitux avatar Feb 17 '16 14:02 carlitux

@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

creeperyang avatar Feb 17 '16 14:02 creeperyang

👍 for [email protected]

SamvelRaja avatar Feb 19 '16 12:02 SamvelRaja

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

MrPeak avatar Feb 23 '16 03:02 MrPeak

:+1 for [email protected]

juancarlosfarah avatar Mar 05 '16 19:03 juancarlosfarah

+1 for [email protected] :+1:

zlargon avatar Mar 08 '16 11:03 zlargon