37

I am trying to decide on a JS test code coverage tool but cannot see clearly the differences between them. The top hits in Google are blanket.js, istanbul-js and JSCover.

Can anyone offer any information on the key differences between them and advantages/disadvantages?

Are there any other useful ones out there?

Christopher Grigg
  • 1,895
  • 20
  • 28

1 Answers1

32

After some trying around i clearly find istanbul the most convenient tool to bring coverage analysis to a node-js project.

  • its installed with npm install
  • it sets up its behavior via the .istanbul.yml
  • gets invoked by its own executable
  • it provides multiple report formats such as clover, lcov, jscoverage, etc.

Istanbul uses the provided executable or js-script to perform the tests and collect coverage information. It can be installed via npm:

npm install istanbul mocha

after successful installation simply invoke it by

./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha

respect the '_' since mocha forks the _mocha-executable as stated here

blanket.js for nodejs integrates easily by

  • its installed with npm install
  • configuring its behavior via the package.json
  • getting invoked by mocha by requiring blanket at commandline
  • generating statistics that are interpreted by mocha's reporters, i.e. html-cov
  • can be used in browser JS

basically it is ready to use after doing

npm install blanket mocha

after successful installation simply run your mocha tests like that

./node_modules/.bin/mocha --require blanket --reporter html-cov >coverage.html

Unfortunately you have to invoke the mocha tests twice if you want to collect coverage information as well as collect test reports since you can only provide one reporter to mocha.

I can not say anything about JSCover since its installation was to complicated for me. Important for me was that i do not have to install any packages as root or even compile things since it becomes more complicated for other users to create a development environment.

smoebody
  • 594
  • 5
  • 12
  • So which one do you personally use? Istanbul or blanket? – Igor Malyk Feb 08 '16 at 14:43
  • 3
    @IgorMalyk i use istanbul since i do not want to perform the tests twice, which is what you have to do for blanket if you want test results and coverage results. With istanbul you perform the tests and automatically get the results as well as coverage analysis – smoebody Feb 08 '16 at 14:49
  • Re. multiple reporters in mocha/running tests twice: It is simple to use multiple reporters with mocha by using [mocha-multi](https://www.npmjs.com/package/mocha-multi) or [mocha-multi-reporters](https://www.npmjs.com/package/mocha-multi-reporters). There is [ongoing work](https://github.com/mochajs/mocha/pull/2184) to implement native support for multiple reporters in mocha. – giraffe.guru Apr 20 '17 at 21:01