0

I was testing my app with Jest, but how it's so hard to find documentation on internet I changed to Mocha

Now I'm trying to generate the coverage.

In my package.json I put the line to test:

scripts: {
     ...
     "test": "mocha './src/__tests__/**/*.test.js' --compilers js:babel-core/register"
}

What do I need to generate the coverage with Istanbul or something else?

lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
Luiz Fumes
  • 41
  • 6
  • Possible duplicate of [Running Mocha + Istanbul + Babel](http://stackoverflow.com/questions/33621079/running-mocha-istanbul-babel) – Louis May 30 '16 at 10:36
  • Possible duplicate of [Code coverage with Mocha](https://stackoverflow.com/questions/16633246/code-coverage-with-mocha) – lifeisfoo Jul 18 '17 at 11:19

2 Answers2

1

You can use isparta for code coverage since it will give the coverage for the ES6 code rather than ES5 code. Here is a very good article which I followed to generate the code coverage: https://onsen.io/blog/mocha-chaijs-unit-test-coverage-es6/. Please do check it and let me know if you are able to generate the coverage.

phkavitha
  • 817
  • 1
  • 9
  • 26
1

This is what I use in my scripts block (among others):

  "scripts": {
    "cover": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -R spec test"
  }
Andrew Eddie
  • 988
  • 6
  • 15