UNPKG

3.94 kBMarkdownView Raw
1# Codacy Coverage Reporter
2[Codacy](https://codacy.com/) support for Node.js. Get coverage reporting and code analysis for Node.js from Codacy.
3
4[![Build Status](https://travis-ci.org/codacy/node-codacy-coverage.svg?branch=1.0.0)](https://travis-ci.org/codacy/node-codacy-coverage)
5[![npm](https://img.shields.io/npm/v/codacy.svg)](https://www.npmjs.com/package/codacy)
6[![npm](https://img.shields.io/npm/dm/codacy.svg)](https://www.npmjs.com/package/codacy)
7[![Codacy](https://www.codacy.com/project/badge/d1bfdf020cc044bb8a2020d009378733)](https://www.codacy.com/public/davidtpate/codacy)
8[![David](https://img.shields.io/david/codacy/node-codacy-coverage.svg)](https://david-dm.org/codacy/node-codacy-coverage)
9[![David](https://img.shields.io/david/dev/codacy/node-codacy-coverage.svg)](https://david-dm.org/codacy/node-codacy-coverage)
10[![David](https://img.shields.io/david/peer/codacy/node-codacy-coverage.svg)](https://david-dm.org/codacy/node-codacy-coverage)
11
12##Installation:
13Add the latest version of `codacy-coverage` to your package.json:
14```
15npm install codacy-coverage --save
16```
17
18If you're using mocha, add `mocha-lcov-reporter` to your package.json:
19```
20npm install mocha-lcov-reporter --save
21```
22
23##Usage:
24
25This script ( `bin/codacy-coverage.js` ) can take standard input from any tool that emits the lcov data format (including [mocha](http://visionmedia.github.com/mocha/)'s [LCov reporter](https://npmjs.org/package/mocha-lcov-reporter)) and send it to Codacy to report your code coverage there.
26
27Once your app is instrumented for coverage, and building, you need to pipe the lcov output to `./node_modules/codacy-coverage/bin/codacy-coverage.js`.
28
29You'll need to provide the Report token from Codacy via an environment variable:
30* CODACY_REPO_TOKEN (the secret repo token from Codacy.com)
31
32### [Mocha](http://visionmedia.github.io/mocha/) + [Blanket.js](https://github.com/alex-seville/blanket)
33- Install [blanket.js](http://blanketjs.org/)
34- Configure blanket according to [docs](https://github.com/alex-seville/blanket/blob/master/docs/getting_started_node.md).
35- Run your tests with a command like this:
36
37```sh
38NODE_ENV=test YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha \
39 --require blanket \
40 --reporter mocha-lcov-reporter | ./node_modules/codacy-coverage/bin/codacy-coverage.js
41```
42### [Mocha](http://visionmedia.github.io/mocha/) + [JSCoverage](https://github.com/fishbar/jscoverage)
43
44Instrumenting your app for coverage is probably harder than it needs to be (read [here](http://www.seejohncode.com/2012/03/13/setting-up-mocha-jscoverage/)), but that's also a necessary step.
45
46In mocha, if you've got your code instrumented for coverage, the command for a travis build would look something like this:
47```sh
48YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha test -R mocha-lcov-reporter | ./node_modules/codacy-coverage/bin/codacy-coverage.js
49```
50### [Istanbul](https://github.com/gotwarlost/istanbul)
51
52**With Mocha:**
53
54```sh
55istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/codacy-coverage/bin/codacy-coverage.js && rm -rf ./coverage
56```
57
58**With Jasmine:**
59
60```sh
61istanbul cover jasmine-node --captureExceptions spec/ && cat ./coverage/lcov.info | ./node_modules/codacy-coverage/bin/codacy-coverage.js && rm -rf ./coverage
62```
63
64### [Poncho](https://github.com/deepsweet/poncho)
65Client-side JS code coverage using [PhantomJS](https://github.com/ariya/phantomjs), [Mocha](https://github.com/visionmedia/mocha) and [Blanket](https://github.com/alex-seville/blanket):
66- [Configure](http://visionmedia.github.io/mocha/#browser-support) Mocha for browser
67- [Mark](https://github.com/deepsweet/poncho#usage) target script(s) with `data-cover` html-attribute
68- Run your tests with a command like this:
69
70```sh
71./node_modules/.bin/poncho -R lcov test/test.html | ./node_modules/codacy-coverage/bin/codacy-coverage.js
72```
73
74## License
75[MIT](LICENSE)