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