1 | # Node Codacy Coverage
|
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://api.codacy.com/project/badge/grade/3c7f5de6ce734762981d3e689de7b941)](https://www.codacy.com/app/codacy/node-codacy-coverage)
|
10 | [![Codacy](https://api.codacy.com/project/badge/coverage/3c7f5de6ce734762981d3e689de7b941)](https://www.codacy.com/app/codacy/node-codacy-coverage)
|
11 | [![David](https://img.shields.io/david/codacy/node-codacy-coverage.svg)](https://david-dm.org/codacy/node-codacy-coverage)
|
12 | [![David](https://img.shields.io/david/dev/codacy/node-codacy-coverage.svg)](https://david-dm.org/codacy/node-codacy-coverage)
|
13 | [![David](https://img.shields.io/david/peer/codacy/node-codacy-coverage.svg)](https://david-dm.org/codacy/node-codacy-coverage)
|
14 |
|
15 | ## Installation:
|
16 | Add the latest version of `codacy-coverage` to your package.json:
|
17 | ```
|
18 | npm install codacy-coverage --save
|
19 | ```
|
20 |
|
21 | If you're using mocha, add `mocha-lcov-reporter` to your package.json:
|
22 | ```
|
23 | npm install mocha-lcov-reporter --save
|
24 | ```
|
25 |
|
26 | ## Usage:
|
27 |
|
28 | 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.
|
29 |
|
30 | Once your app is instrumented for coverage, and building, you need to pipe the lcov output to `./node_modules/.bin/codacy-coverage`.
|
31 |
|
32 | You'll need to provide the Report token from Codacy via an environment variable:
|
33 | * CODACY_PROJECT_TOKEN (the secret repo token from Codacy.com)
|
34 |
|
35 | > Note: You should keep your API token well **protected**, as it grants owner permissions to your projects.
|
36 |
|
37 | **Enterprise**
|
38 |
|
39 | To send coverage in the enterprise version you should specify your Codacy installation URL:
|
40 | ```
|
41 | codacy-coverage -e <YOUR-URL>:16006
|
42 | ```
|
43 |
|
44 | ### [Mocha](http://mochajs.org) + [Blanket.js](https://github.com/alex-seville/blanket)
|
45 | - Install [blanket.js](http://blanketjs.org/)
|
46 | - Configure blanket according to [docs](https://github.com/alex-seville/blanket/blob/master/docs/getting_started_node.md).
|
47 | - Run your tests with a command like this:
|
48 |
|
49 | ```sh
|
50 | NODE_ENV=test YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha \
|
51 | --require blanket \
|
52 | --reporter mocha-lcov-reporter | ./node_modules/.bin/codacy-coverage
|
53 | ```
|
54 | ### [Mocha](http://mochajs.org) + [JSCoverage](https://github.com/fishbar/jscoverage)
|
55 |
|
56 | 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.
|
57 |
|
58 | In mocha, if you've got your code instrumented for coverage, the command for a travis build would look something like this:
|
59 | ```sh
|
60 | YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha test -R mocha-lcov-reporter | ./node_modules/.bin/codacy-coverage
|
61 | ```
|
62 | ### [Istanbul](https://github.com/gotwarlost/istanbul)
|
63 |
|
64 | **With Mocha:**
|
65 |
|
66 | ```sh
|
67 | istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage && rm -rf ./coverage
|
68 | ```
|
69 |
|
70 | **With Jasmine:**
|
71 |
|
72 | ```sh
|
73 | istanbul cover jasmine-node --captureExceptions spec/ && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage && rm -rf ./coverage
|
74 | ```
|
75 |
|
76 | ### [Grunt](http://gruntjs.com/)
|
77 | - Install & Configure [grunt-codacy](https://www.npmjs.com/package/grunt-codacy)
|
78 |
|
79 | ### [Poncho](https://github.com/deepsweet/poncho)
|
80 | Client-side JS code coverage using [PhantomJS](https://github.com/ariya/phantomjs), [Mocha](http://mochajs.org) and [Blanket](https://github.com/alex-seville/blanket):
|
81 | - [Configure](http://mochajs.org#browser-support) Mocha for browser
|
82 | - [Mark](https://github.com/deepsweet/poncho#usage) target script(s) with `data-cover` html-attribute
|
83 | - Run your tests with a command like this:
|
84 |
|
85 | ```sh
|
86 | ./node_modules/.bin/poncho -R lcov test/test.html | ./node_modules/.bin/codacy-coverage
|
87 | ```
|
88 |
|
89 | ### [gulp](http://gulpjs.com/)
|
90 | - Install & Configure [gulp-codacy](https://www.npmjs.com/package/gulp-codacy)
|
91 |
|
92 | ### Custom Language (Typescript, Coffeescript)
|
93 |
|
94 | - Pass an extra parameter to the codacy-coverage reporter `--language typescript` or `--language coffeescript`.
|
95 | - If you have multiple language you need to invoke the reporter once for each of them.
|
96 |
|
97 | ### Troubleshooting
|
98 |
|
99 | The paths in your coverage file should be relative, if you are having problems with absolute paths, you can run our plugin with `-p .` to strip the current path from the paths in your coverage file:
|
100 | ```
|
101 | cat ./coverage/lcov.info | node_modules/.bin/codacy-coverage -p .
|
102 | ```
|
103 |
|
104 | To send coverage in the <strong>enterprise</strong> version you should specify your Codacy installation URL followed by the port 16006 using the -e option, example:
|
105 | ```
|
106 | cat ./coverage/lcov.info | node_modules/.bin/codacy-coverage -e <YOUR-URL>:16006
|
107 | ```
|
108 |
|
109 | ## License
|
110 | [MIT](LICENSE)
|
111 |
|
112 | ## What is Codacy?
|
113 |
|
114 | [Codacy](https://www.codacy.com/) is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.
|
115 |
|
116 | ### Among Codacy’s features:
|
117 |
|
118 | - Identify new Static Analysis issues
|
119 | - Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
|
120 | - Auto-comments on Commits and Pull Requests
|
121 | - Integrations with Slack, HipChat, Jira, YouTrack
|
122 | - Track issues Code Style, Security, Error Proneness, Performance, Unused Code and other categories
|
123 |
|
124 | Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.
|
125 |
|
126 | Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.
|
127 |
|
128 | ### Free for Open Source
|
129 |
|
130 | Codacy is free for Open Source projects.
|