|
1 | 1 | # Node Codacy Coverage |
| 2 | + |
2 | 3 | Credits to [David](https://github.com/DavidTPate) for creating this! |
3 | 4 | [Codacy](https://codacy.com/) support for Node.js. Get coverage reporting and code analysis for Node.js from Codacy. |
4 | 5 |
|
5 | | - |
| 6 | +[](https://www.codacy.com/app/codacy/node-codacy-coverage) |
| 7 | +[](https://www.codacy.com/app/codacy/node-codacy-coverage) |
6 | 8 | [](https://circleci.com/gh/codacy/node-codacy-coverage) |
7 | 9 | [](https://www.npmjs.com/package/codacy-coverage) |
8 | 10 | [](https://www.npmjs.com/package/codacy-coverage) |
9 | | -[](https://www.codacy.com/app/codacy/node-codacy-coverage) |
10 | | -[](https://www.codacy.com/app/codacy/node-codacy-coverage) |
11 | 11 | [](https://david-dm.org/codacy/node-codacy-coverage) |
12 | 12 | [](https://david-dm.org/codacy/node-codacy-coverage) |
13 | 13 | [](https://david-dm.org/codacy/node-codacy-coverage) |
14 | 14 |
|
15 | | -## Installation: |
| 15 | +## Installation |
| 16 | + |
16 | 17 | Add the latest version of `codacy-coverage` to your package.json: |
17 | | -``` |
| 18 | + |
| 19 | +```sh |
18 | 20 | npm install codacy-coverage --save |
19 | 21 | ``` |
20 | 22 |
|
21 | 23 | If you're using mocha, add `mocha-lcov-reporter` to your package.json: |
22 | | -``` |
| 24 | + |
| 25 | +```sh |
23 | 26 | npm install mocha-lcov-reporter --save |
24 | 27 | ``` |
25 | 28 |
|
26 | | -## Usage: |
| 29 | +## Enterprise |
27 | 30 |
|
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. |
| 31 | +To send coverage in the enterprise version you should specify your Codacy installation URL: |
| 32 | + |
| 33 | +```sh |
| 34 | +codacy-coverage -e <YOUR-CODACY-ENTERPRISE-URL>:16006 |
| 35 | +``` |
29 | 36 |
|
30 | | -Once your app is instrumented for coverage, and building, you need to pipe the lcov output to `./node_modules/.bin/codacy-coverage`. |
| 37 | +## Usage |
| 38 | + |
| 39 | +This cli 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. |
| 40 | + |
| 41 | +Once your app is instrumented for coverage, and building, you need to pipe the lcov output to `codacy-coverage`. |
31 | 42 |
|
32 | 43 | You'll need to provide the Report token from Codacy via an environment variable: |
| 44 | + |
33 | 45 | * CODACY_PROJECT_TOKEN (the secret repo token from Codacy.com) |
34 | 46 |
|
35 | 47 | > Note: You should keep your API token well **protected**, as it grants owner permissions to your projects. |
36 | 48 |
|
37 | | -**Enterprise** |
| 49 | +### [Mocha](http://mochajs.org) + [Blanket.js](https://github.com/alex-seville/blanket) |
38 | 50 |
|
39 | | -To send coverage in the enterprise version you should specify your Codacy installation URL: |
40 | | -``` |
41 | | -codacy-coverage -e <YOUR-URL>:16006 |
| 51 | +* Install [blanket.js](http://blanketjs.org/) |
| 52 | +* Configure blanket according to [docs](https://github.com/alex-seville/blanket/blob/master/docs/getting_started_node.md). |
| 53 | +* Add test with coverage step to your package.json: |
| 54 | + |
| 55 | +```json |
| 56 | +"scripts": { |
| 57 | + "test-with-coverage": "NODE_ENV=test YOURPACKAGE_COVERAGE=1 mocha --require blanket --reporter mocha-lcov-reporter | codacy-coverage" |
| 58 | +} |
42 | 59 | ``` |
43 | 60 |
|
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: |
| 61 | +* Run your tests with: |
48 | 62 |
|
49 | 63 | ```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 |
| 64 | +npm run test-with-coverage |
53 | 65 | ``` |
| 66 | + |
54 | 67 | ### [Mocha](http://mochajs.org) + [JSCoverage](https://github.com/fishbar/jscoverage) |
55 | 68 |
|
56 | 69 | 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 | 70 |
|
58 | | -In mocha, if you've got your code instrumented for coverage, the command for a travis build would look something like this: |
| 71 | +* Add test with coverage step to your package.json: |
| 72 | + |
| 73 | +```json |
| 74 | +"scripts": { |
| 75 | + "test-with-coverage": "YOURPACKAGE_COVERAGE=1 mocha test -R mocha-lcov-reporter | codacy-coverage" |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +* Run your tests with: |
| 80 | + |
59 | 81 | ```sh |
60 | | -YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha test -R mocha-lcov-reporter | ./node_modules/.bin/codacy-coverage |
| 82 | +npm run test-with-coverage |
61 | 83 | ``` |
| 84 | + |
62 | 85 | ### [Istanbul](https://github.com/gotwarlost/istanbul) |
63 | 86 |
|
64 | | -**With Mocha:** |
| 87 | +#### With Mocha |
65 | 88 |
|
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 |
| 89 | +* Add test with coverage step to your package.json: |
| 90 | + |
| 91 | +```json |
| 92 | +"scripts": { |
| 93 | + "test-with-coverage": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | codacy-coverage && rm -rf ./coverage" |
| 94 | +} |
68 | 95 | ``` |
69 | 96 |
|
70 | | -**With Jasmine:** |
| 97 | +* Run your tests with: |
71 | 98 |
|
72 | 99 | ```sh |
73 | | -istanbul cover jasmine-node --captureExceptions spec/ && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage && rm -rf ./coverage |
| 100 | +npm run test-with-coverage |
74 | 101 | ``` |
75 | 102 |
|
76 | | -### [Grunt](http://gruntjs.com/) |
77 | | -- Install & Configure [grunt-codacy](https://www.npmjs.com/package/grunt-codacy) |
| 103 | +#### With Jasmine |
| 104 | + |
| 105 | +* Add test with coverage step to your package.json: |
| 106 | + |
| 107 | +```json |
| 108 | +"scripts": { |
| 109 | + "test-with-coverage": "istanbul cover jasmine-node --captureExceptions spec/ && cat ./coverage/lcov.info | codacy-coverage && rm -rf ./coverage" |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +* Run your tests with: |
| 114 | + |
| 115 | +```sh |
| 116 | +npm run test-with-coverage |
| 117 | +``` |
78 | 118 |
|
79 | 119 | ### [Poncho](https://github.com/deepsweet/poncho) |
| 120 | + |
80 | 121 | 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: |
| 122 | + |
| 123 | +* [Configure](http://mochajs.org#browser-support) Mocha for browser |
| 124 | +* [Mark](https://github.com/deepsweet/poncho#usage) target script(s) with `data-cover` html-attribute |
| 125 | +* Add test with coverage step to your package.json: |
| 126 | + |
| 127 | +```json |
| 128 | +"scripts": { |
| 129 | + "test-with-coverage": "poncho -R lcov test/test.html | codacy-coverage" |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +* Run your tests with: |
84 | 134 |
|
85 | 135 | ```sh |
86 | | -./node_modules/.bin/poncho -R lcov test/test.html | ./node_modules/.bin/codacy-coverage |
| 136 | +npm run test-with-coverage |
87 | 137 | ``` |
88 | 138 |
|
89 | | -### [gulp](http://gulpjs.com/) |
90 | | -- Install & Configure [gulp-codacy](https://www.npmjs.com/package/gulp-codacy) |
| 139 | +## Extras |
91 | 140 |
|
92 | | -### Custom Language (Typescript, Coffeescript) |
| 141 | +### Force custom language (e.g. Typescript, Coffeescript, C, ...) |
93 | 142 |
|
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. |
| 143 | +* Pass an extra parameter to the codacy-coverage reporter `--language typescript` or `--language coffeescript`. |
| 144 | +* If you have multiple languages you need to invoke the reporter for each of them. |
96 | 145 |
|
97 | | -### Troubleshooting |
| 146 | +## Troubleshooting |
98 | 147 |
|
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 | | -``` |
| 148 | +### Path Problems |
| 149 | + |
| 150 | +The paths in your coverage file should be relative, |
| 151 | +if you are having problems with absolute paths, |
| 152 | +you can run our plugin with `-p .` to strip the current path from the paths in your coverage file: |
103 | 153 |
|
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: |
| 154 | +```json |
| 155 | +"scripts": { |
| 156 | + "test-with-coverage": "cat ./coverage/lcov.info | codacy-coverage -p ." |
| 157 | +} |
105 | 158 | ``` |
106 | | -cat ./coverage/lcov.info | node_modules/.bin/codacy-coverage -e <YOUR-URL>:16006 |
| 159 | + |
| 160 | +### Enterprise Coverage |
| 161 | + |
| 162 | +To send coverage in the **enterprise** version you should specify your Codacy installation URL followed by the port 16006 using the -e option, example: |
| 163 | + |
| 164 | +```json |
| 165 | +"scripts": { |
| 166 | + "test-with-coverage": "cat ./coverage/lcov.info | codacy-coverage -e <YOUR-CODACY-ENTERPRISE-URL>:16006" |
| 167 | +} |
107 | 168 | ``` |
108 | 169 |
|
109 | 170 | ## License |
| 171 | + |
110 | 172 | [MIT](LICENSE) |
111 | 173 |
|
112 | | -## What is Codacy? |
| 174 | +## What is Codacy |
113 | 175 |
|
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. |
| 176 | +[Codacy](https://www.codacy.com/) is an Automated Code Review Tool that monitors your technical debt, |
| 177 | +helps you improve your code quality, |
| 178 | +teaches best practices to your developers, |
| 179 | +and helps you save time in Code Reviews. |
115 | 180 |
|
116 | | -### Among Codacy’s features: |
| 181 | +### Among Codacy’s features |
117 | 182 |
|
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 |
| 183 | +* Identify new Static Analysis issues |
| 184 | +* Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories) |
| 185 | +* Auto-comments on Commits and Pull Requests |
| 186 | +* Integrations with Slack, HipChat, Jira, YouTrack |
| 187 | +* Track issues Code Style, Security, Error Proneness, Performance, Unused Code and other categories |
123 | 188 |
|
124 | 189 | Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity. |
125 | 190 |
|
|
0 commit comments