| 1 |
# Integrating with codecov.io |
| 2 |
|
| 3 |
[codecov](https://codecov.io/) is a great tool for adding coverage reports to your GitHub project, even viewing them inline on GitHub with a [browser extension](https://docs.codecov.io/docs/browser-extension). |
| 4 |
|
| 5 |
## Quick start |
| 6 |
|
| 7 |
Assuming your `npm test` does not run `nyc` and you have the `npx` executable (npm v5.2+), have your CI runner execute the following: |
| 8 |
|
| 9 |
```shell |
| 10 |
npx nyc --reporter=lcov npm test && npx codecov |
| 11 |
``` |
| 12 |
|
| 13 |
## Without `npx` - Travis CI example using npm scripts |
| 14 |
|
| 15 |
1. add the codecov and nyc dependencies: |
| 16 |
|
| 17 |
```shell |
| 18 |
npm install codecov nyc --save-dev |
| 19 |
``` |
| 20 |
|
| 21 |
2. update the scripts in your package.json to include these lines (replace `mocha` with your test runner): |
| 22 |
|
| 23 |
```json |
| 24 |
{ |
| 25 |
"scripts": { |
| 26 |
"test": "nyc --reporter=lcov mocha", |
| 27 |
"coverage": "codecov" |
| 28 |
} |
| 29 |
} |
| 30 |
``` |
| 31 |
|
| 32 |
3. For private repos, add the environment variable `CODECOV_TOKEN` to Travis CI. |
| 33 |
|
| 34 |
4. add the following to your `.travis.yml`: |
| 35 |
|
| 36 |
```yaml |
| 37 |
after_success: npm run coverage |
| 38 |
``` |