Istanbul: No coverage information was collected

Created on 22 May 2015  路  14Comments  路  Source: gotwarlost/istanbul

Hello,

I've read all the issues regarding the problem, but none of the solutions worked for me.
I run this command via npm test:

istanbul cover -v node_modules/mocha/bin/_mocha -- -R spec

All my tests pass, but no coverage information is collected. I get: "No coverage information was collected, exit without writing coverage information".

verbose: true
instrumentation:
    root: .
    default-excludes: true
    excludes: []
    embed-source: false
    variable: __coverage__
    compact: true
    preserve-comments: false
    complete-copy: false
    save-baseline: false
    baseline-file: ./coverage/coverage-baseline.json
    include-all-sources: false
    include-pid: false
    preload-sources: false
reporting:
    print: summary
    reports:
        - lcov
    dir: ./coverage
    watermarks:
        statements: [50, 80]
        lines: [50, 80]
        functions: [50, 80]
        branches: [50, 80]
    report-config:
        clover: {"file": "clover.xml"}
        cobertura: {"file": "cobertura-coverage.xml"}
        json: {"file": "coverage-final.json"}
        json-summary: {"file": "coverage-summary.json"}
        lcovonly: {"file": "lcov.info"}
        teamcity: {"file": null}
        text: {"file": null, "maxCols": 0}
        text-summary: {"file": null}
hooks:
    hook-run-in-context: true
    post-require-hook: null
    handle-sigint: false
check:
    global:
        statements: 0
        lines: 0
        branches: 0
        functions: 0
        excludes: []
    each:
        statements: 0
        lines: 0
        branches: 0
        functions: 0
        excludes: []

I have no idea what to do and how to make it work. I would appreciate any kind of advice.

question

Most helpful comment

I've had similar issues using a transpiler, this works for me with istanbul 1.0.0-alpha.2
babel-node ./node_modules/istanbul/lib/cli.js --include-all-sources cover ./node_modules/.bin/_mocha -- ./tests/ -R spec --recursive

All 14 comments

Can I get the repo that you are running it on? Is it public?

Thank you for a quick response.
Sorry, but I can't grant you access to the actual repository.
I'm using mocha for testing react components so I use a compiler for mocha similar to this:

// tests/compiler.js
var fs = require('fs'),
    ReactTools = require('react-tools'),
    origJs = require.extensions['.js'];

require.extensions['.js'] = function(module, filename) {
  if (filename.indexOf('node_modules/') >= 0) {
    return (origJs || require.extensions['.js'])(module, filename);
  }
  var content = fs.readFileSync(filename, 'utf8');
  var compiled = ReactTools.transform(content, {harmony: true});
  return module._compile(compiled, filename);
};

Could this cause the problem?
Or is it because my test folder is not in src directory? My project structure looks roughly like this:

src
test
package.json

Hello again,

I've managed to create a small project representing the issue. Run npm install and then npm test:
https://github.com/Donaira/react-istanbul

You'll see the warning "No coverage information was collected".

I'm worried that's because of the compiler I use for mocha? If that's so, could you suggest any solutions?

Yup, that's exactly the issue you are seeing. istanbul also hijacks the require in order to instrument the code. I hacked around on it a bit this morning, but I didn't figure out the proper way to do both of these hooks. I'll try to take a look at it later, but you may have to handle the instrumentation on your own since you are also handling the require on your own too.

@Donaira I had the same issue. Use --compilers js:babel/register and it works perfectly fine.

Using twinschild suggested compiler didn't work, I switched to gulp-jsx-coverage which uses babel, istanbul and mocha. Thanks for your input :)

+1

Try this: istanbul cover -v node_modules/mocha/bin/_mocha -- --compilers js:babel/register,.:tests/compiler.js --require ./tests/setup.js -R spec
where ./tests/setup.js is any React component set up that is needed.

I'm running into the same problem. I tried several variations and then some. I found this also: https://github.com/gotwarlost/istanbul-no-coverage/commit/5e41ea4aa2b3ebdc76820403fb061523d8419ac5 and tried node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- -R spec and several variations off that.

I just started messing with mocha, chai, supertest, and istanbul so I may be missing something. My devDependencies looks like this:

"devDependencies": {
    "chai": "^3.4.1",
    "istanbul": "^0.4.2",
    "mocha": "^2.3.4",
    "supertest": "^1.1.0"
}

I'm not using babel. I have only two tests and they are both passing:

$ istanbul cover _mocha -- -R nyan
 2   -_-_,------,
 0   -_-_|   /\_/\ 
 0   -_-^|__( ^ .^) 
     -_-  ""  "" 

  2 passing (225ms)

No coverage information was collected, exit without writing coverage information

I ran into the same problem with my repo. I run the following command and it only generate the coverage for my compiler.js (which is not the thing that I want).

"coverage": "NODE_ENV=test PORT=3001 istanbul cover ./node_modules/.bin/_mocha -- --compilers js:compiler.js 'app/**/*-test.js' 'tests/**/*.js'",

I've had similar issues using a transpiler, this works for me with istanbul 1.0.0-alpha.2
babel-node ./node_modules/istanbul/lib/cli.js --include-all-sources cover ./node_modules/.bin/_mocha -- ./tests/ -R spec --recursive

I tried what @szilveszter9 is suggesting, however I am now getting Unexpected token < error, and I am assuming that my react-template files are not being compiled (since I removed the --compilers).

with --compilers - I get back to the same behavior.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasonpincin picture jasonpincin  路  22Comments

lizhexia picture lizhexia  路  60Comments

amoufaddel picture amoufaddel  路  28Comments

dcrockwell picture dcrockwell  路  37Comments

NiGhTTraX picture NiGhTTraX  路  36Comments