istanbul icon indicating copy to clipboard operation
istanbul copied to clipboard

Empty coverage directory, no errors

Open mscdex opened this issue 9 years ago • 12 comments

Running istanbul -v cover test/test-foo.js shows several Module load hook: transform messages (one for each of my files in ./lib) and it creates a ./coverage directory, but it's empty when the process exits. There are no other messages after the transform messages.

I'm not using any special test runner like mocha, test/test-foo.js just executes various test cases against/using files from ./lib.

I'm also executing istanbul on Windows if that makes any difference.

mscdex avatar Sep 06 '15 21:09 mscdex

Are you loading your test cases in a subprocess?

gotwarlost avatar Oct 06 '15 22:10 gotwarlost

I am also having the same issue.. i run istanbul against a folder which has jasmine unit test cases written.. all the test cases are executed and an empty coverage folder is generated.

May i know the solution on how to fix this?

VinayKumarSarda avatar Oct 26 '15 11:10 VinayKumarSarda

@mscdex any fix did you get for the above??

VinayKumarSarda avatar Oct 26 '15 11:10 VinayKumarSarda

@gotwarlost Any suggesstion?

VinayKumarSarda avatar Oct 27 '15 09:10 VinayKumarSarda

@gotwarlost Can you please help in resolving the same?

VinayKumarSarda avatar Oct 30 '15 09:10 VinayKumarSarda

There is too little information for me to guess as to what is going on. Some things that can interfere with coverage are:

  • running tests in subprocesses
  • an exit handler for the process being set which somehow stops the istanbul exit handler from writing the reports

gotwarlost avatar Oct 31 '15 00:10 gotwarlost

I've got the same behaviour, I'm running istanbul cover _mocha and I get No coverage information was collected, exit without writing coverage information and an empty coverage directory. On the contrary, if I cd to the default test directory and run the following command istanbul cover _mocha -- . I get the summary and coverage file in place in the root directory.

cjoach avatar Nov 23 '15 01:11 cjoach

I'm having the same issue and it can be fixed, as @cacplate states, by cd'ing into the test directory and running from there: istanbul cover _mocha -- ./

To recreate...

  1. create a default express app
  2. place unit test in test/lib/test.api.js
  3. place module in lib/api.js

From project root:

$ istanbul cover _mocha -- ./tests/*
[TypeError: Cannot read property 'Kerberos' of undefined]

  API
no error
    ✓ get tasks

  User
no error
   username:  test-12345
    ✓ find a user by username

  2 passing (130ms)

No coverage information was collected, exit without writing coverage information

From inside the tests directory:

$ istanbul cover _mocha -- ./*
[TypeError: Cannot read property 'Kerberos' of undefined]

  API
no error
    ✓ get tasks

  User
no error
   username:  test-12345
    ✓ find a user by username

  2 passing (155ms)

=============================================================================
Writing coverage object [/path/to/projects/tests/coverage/coverage.json]
Writing coverage reports at [/path/to/projects/tests/coverage]
=============================================================================
=============================== Coverage summary ===============================
Statements   : 95% ( 38/40 )
Branches     : 50% ( 2/4 )
Functions    : 100% ( 15/15 )
Lines        : 100% ( 38/38 )
================================================================================

Stack details:

  • node v5.5.0
  • npm 2.11.3
  • mocha 2.4.5
  • istanbul 0.4.2
  • mocha-istanbul 0.2.0
  • should 8.2.1

daithi-coombes avatar Feb 04 '16 16:02 daithi-coombes

If running istanbul inside test directory works, then

istanbul cover --root test _mocha

in parent directory should probably work.

Velenir avatar Nov 16 '16 14:11 Velenir

I am also having the same issue. I am using istanbul with mocha. By the way, my coverage reports were creating before. But now not creating. I'm using below command. $ npm run cover There is below my package.json: "scripts": { "test": "node_modules/.bin/mocha --reporter spec", "cover": "node node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -R" },

Tests are run successful. But coverage directory is empty.

Edit: I solved my problem. Problem is a infinite loop in my test code. Thanks...

YARARMAN avatar Dec 05 '17 12:12 YARARMAN

The problem is, Mocha is not exiting after its execution. So coverage report is unable to printout as the execution id hold by mocha. In Script of package.json mention --exit after mocha. EX- nyc --reporter=html --reporter=text mocha --exit

sibajeeray avatar Jul 04 '18 10:07 sibajeeray

The problem is, Mocha is not exiting after its execution. So coverage report is unable to printout as the execution id hold by mocha. In Script of package.json mention --exit after mocha. EX- nyc --reporter=html --reporter=text mocha --exit

it solved. thanks

20-07 avatar Apr 21 '20 10:04 20-07