gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 787 forks source link

Istanbul Doesn't Integrate with Mocha #727

Open frankpiva opened 8 years ago

frankpiva commented 8 years ago

I've been looking at Istanbul for the better part of two days now, and I have not been able to use it on my Mocha unit tests. Despite the many different argument(s)/option(s) combinations I have tried I always get the error "ReferenceError: describe is not defined". I have both Istanbul and Mocha installed globally. I have also tried to manually import describe and it, so that Istanbul wouldn't barf of them, but that did not work either. I'm running out of options and will use another tool if I can't get it to work by the end of today.

RockyRoad29 commented 8 years ago

Hi there, I was hitting the same issue, but was lucky enough to find this post where the question mentions

running istanbul cover _mocha

Just tried it and it worked like a charm for me. It's a pity it is not documented and explained. This (not mine) might help too.

twotwo commented 6 years ago

thanks @RockyRoad29 , works for me

RockyRoad29 commented 6 years ago

welcome @twotwo .

But according to this project's deprecation notice you might want to switch to https://istanbul.js.org/ .

The package.json for a new project might look like:

{
  "name": "some-node-proj",
  "version": "0.1.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "nyc mocha"
  },
  "keywords": [],
  "author": "your name",
  "license": "AGPL-3.0+",
  "devDependencies": {
    "mocha": "^4.1.0",
    "nyc": "^11.4.1"
  },
  "nyc": {
    "reporter": [
      "lcov",
      "text-summary"
    ]
  }
}

Then you run tests and coverage at once with the proper environment, from any subdirectory, with the shell command:

 $ npm test