UNPKG

8.97 kBMarkdownView Raw
1# node-coveralls
2
3[![Build Status][ci-image]][ci-url] [![Coverage Status][coveralls-image]][coveralls-url]
4
5[Coveralls.io](https://coveralls.io/) support for Node.js. Get the great coverage reporting of coveralls.io and add a cool coverage button (like the one above) to your README.
6
7## Supported CI services:
8
9* [Travis CI](https://travis-ci.org/)
10* [CodeShip](https://codeship.com/)
11* [CircleCI](https://circleci.com/)
12* [Jenkins](https://jenkins.io/)
13* [Gitlab CI](https://gitlab.com/)
14* [AppVeyor](https://www.appveyor.com/)
15* [Buildkite](https://buildkite.com/)
16* [GitHub Actions CI](https://github.com/features/actions)
17* [CodeFresh](https://codefresh.io/)
18
19## Installation:
20
21Add the latest version of `coveralls` to your package.json:
22
23```shell
24npm install coveralls --save-dev
25```
26
27If you're using mocha, add `mocha-lcov-reporter` to your package.json:
28
29```shell
30npm install mocha-lcov-reporter --save-dev
31```
32
33## Usage:
34
35This script `bin/coveralls.js` can take standard input from any tool that emits the lcov data format (including [mocha](https://mochajs.org/)'s [LCOV reporter](https://npmjs.org/package/mocha-lcov-reporter)) and send it to coveralls.io to report your code coverage there.
36
37Once your app is instrumented for coverage, and building, you need to pipe the lcov output to `./node_modules/coveralls/bin/coveralls.js`.
38
39This library currently supports [Travis CI](https://travis-ci.org/) with no extra effort beyond piping the lcov output to coveralls. However, if you're using a different build system, there are a few **necessary** environment variables:
40
41- `COVERALLS_SERVICE_NAME` (the name of your build system)
42- `COVERALLS_REPO_TOKEN` (the secret repo token from coveralls.io)
43- `COVERALLS_GIT_BRANCH` (the branch name)
44
45There are optional environment variables for other build systems as well:
46
47- `COVERALLS_FLAG_NAME` (a flag name to differentiate jobs, e.g. Unit, Functional, Integration)
48- `COVERALLS_SERVICE_NUMBER` (a number that uniquely identifies the build)
49- `COVERALLS_SERVICE_JOB_ID` (an ID that uniquely identifies the build's job)
50- `COVERALLS_SERVICE_JOB_NUMBER` (a number that uniquely identifies the build's job)
51- `COVERALLS_RUN_AT` (a date string for the time that the job ran. RFC 3339 dates work. This defaults to your build system's date/time if you don't set it)
52- `COVERALLS_PARALLEL` (set to `true` when running jobs in parallel, requires a completion webhook. More info here: <https://docs.coveralls.io/parallel-build-webhook>)
53
54### GitHub Actions CI
55
56If you are using GitHub Actions CI, you should look into [coverallsapp/github-action](https://github.com/coverallsapp/github-action).
57
58Parallel runs example [workflow.yml](https://github.com/coverallsapp/coveralls-node-demo/blob/master/.github/workflows/workflow.yml)
59
60### [CircleCI Orb](https://circleci.com/)
61
62Here's our Orb for quick integration: [coveralls/coveralls](https://circleci.com/orbs/registry/orb/coveralls/coveralls)
63
64Workflow example: [config.yml](https://github.com/coverallsapp/coveralls-node-demo/blob/master/.circleci/config.yml)
65
66### [Travis-CI](https://travis-ci.org/)
67
68Parallel jobs example: [.travis.yml](https://github.com/coverallsapp/coveralls-node-demo/blob/master/.travis.yml)
69
70### [Jest](https://jestjs.io/)
71
72- Install [jest](https://jestjs.io/docs/en/getting-started)
73- Use the following to run tests and push files to coveralls on success:
74
75 ```sh
76 jest --coverage && coveralls < coverage/lcov.info
77 ```
78
79Check out an example [here](https://github.com/Ethan-Arrowood/harperdb-connect/blob/master/.travis.yml) which makes use of Travis CI build stages
80
81### [Mocha](https://mochajs.org/) + [Blanket.js](https://github.com/alex-seville/blanket)
82
83- Install [blanket.js](https://github.com/alex-seville/blanket)
84- Configure blanket according to [docs](https://github.com/alex-seville/blanket/blob/master/docs/getting_started_node.md).
85- Run your tests with a command like this:
86
87 ```sh
88 NODE_ENV=test YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha \
89 --require blanket \
90 --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js
91 ```
92
93### [Mocha](https://mochajs.org/) + [JSCoverage](https://github.com/fishbar/jscoverage)
94
95Instrumenting your app for coverage is probably harder than it needs to be (read [here](http://seejohncode.com/2012/03/13/setting-up-mocha-jscoverage/)), but that's also a necessary step.
96
97In mocha, if you've got your code instrumented for coverage, the command for a Travis CI build would look something like this:
98
99```sh
100YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha test -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js
101```
102
103Check out an example [Makefile](https://github.com/cainus/urlgrey/blob/master/Makefile) from one of my projects for an example, especially the test-coveralls build target. Note: Travis CI runs `npm test`, so whatever target you create in your Makefile must be the target that `npm test` runs (This is set in package.json's `scripts` property).
104
105### [Istanbul](https://github.com/gotwarlost/istanbul)
106
107#### With Mocha:
108
109```sh
110istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
111```
112
113#### With Jasmine:
114
115```sh
116istanbul cover jasmine-node --captureExceptions spec/ && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
117```
118
119### [Nodeunit](https://github.com/caolan/nodeunit) + [JSCoverage](https://github.com/fishbar/jscoverage)
120
121Depend on nodeunit, jscoverage, and coveralls:
122
123```sh
124npm install nodeunit jscoverage coveralls --save-dev
125```
126
127Add a coveralls script to "scripts" in your `package.json`:
128
129```json
130"scripts": {
131 "test": "nodeunit test",
132 "coveralls": "jscoverage lib && YOURPACKAGE_COVERAGE=1 nodeunit --reporter=lcov test | coveralls"
133}
134```
135
136Ensure your app requires instrumented code when `process.env.YOURPACKAGE_COVERAGE` variable is defined.
137
138Run your tests with a command like this:
139
140```sh
141npm run coveralls
142```
143
144For detailed instructions on requiring instrumented code, running on Travis CI and submitting to coveralls [see this guide](https://github.com/alanshaw/nodeunit-lcov-coveralls-example).
145
146### [Poncho](https://github.com/deepsweet/poncho)
147
148Client-side JS code coverage using [PhantomJS](https://github.com/ariya/phantomjs), [Mocha](https://mochajs.org/) and [Blanket](https://github.com/alex-seville/blanket):
149
150- [Configure](https://mochajs.org/#running-mocha-in-the-browser) Mocha for browser
151- [Mark](https://github.com/deepsweet/poncho#usage) target script(s) with `data-cover` HTML attribute
152- Run your tests with a command like this:
153
154 ```sh
155 ./node_modules/.bin/poncho -R lcov test/test.html | ./node_modules/coveralls/bin/coveralls.js
156 ```
157
158### [Lab](https://github.com/hapijs/lab)
159
160```sh
161lab -r lcov | ./node_modules/.bin/coveralls
162```
163
164### [nyc](https://github.com/istanbuljs/nyc)
165
166Works with almost any testing framework. Simply execute
167`npm test` with the `nyc` bin followed by running its reporter:
168
169```shell
170nyc npm test && nyc report --reporter=text-lcov | coveralls
171```
172
173### [TAP](https://github.com/tapjs/node-tap)
174
175Simply run your tap tests with the `COVERALLS_REPO_TOKEN` environment
176variable set and tap will automatically use `nyc` to report
177coverage to coveralls.
178
179### Command Line Parameters
180
181```shell
182Usage: coveralls.js [-v] filepath
183```
184
185#### Optional arguments:
186
187- `-v`, `--verbose`
188- `filepath` - optionally defines the base filepath of your source files.
189
190## Running locally
191
192If you're running locally, you must have a `.coveralls.yml` file, as documented in [their documentation](https://docs.coveralls.io/ruby-on-rails#configuration), with your `repo_token` in it; or, you must provide a `COVERALLS_REPO_TOKEN` environment variable on the command-line.
193
194If you want to send commit data to coveralls, you can set the `COVERALLS_GIT_COMMIT` environment-variable to the commit hash you wish to reference. If you don't want to use a hash, you can set it to `HEAD` to supply coveralls with the latest commit data. This requires git to be installed and executable on the current PATH.
195
196## Contributing
197
198I generally don't accept pull requests that are untested or break the build, because I'd like to keep the quality high (this is a coverage tool after all!).
199
200I also don't care for "soft-versioning" or "optimistic versioning" (dependencies that have ^, x, > in them, or anything other than numbers and dots). There have been too many problems with bad semantic versioning in dependencies, and I'd rather have a solid library than a bleeding-edge one.
201
202
203[ci-image]: https://github.com/nickmerwin/node-coveralls/workflows/Tests/badge.svg
204[ci-url]: https://github.com/nickmerwin/node-coveralls/actions?workflow=Tests
205
206[coveralls-image]: https://coveralls.io/repos/nickmerwin/node-coveralls/badge.svg?branch=master&service=github
207[coveralls-url]: https://coveralls.io/github/nickmerwin/node-coveralls?branch=master