{"id":13599557,"url":"https://github.com/codecov/example-node","last_synced_at":"2025-04-06T23:18:20.752Z","repository":{"id":28789977,"uuid":"32312776","full_name":"codecov/example-node","owner":"codecov","description":"Example repo for uploading reports to Codecov","archived":false,"fork":false,"pushed_at":"2024-01-22T20:34:27.000Z","size":60,"stargazers_count":193,"open_issues_count":4,"forks_count":74,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-03-30T21:09:52.043Z","etag":null,"topics":["istanbul","javascript","node"],"latest_commit_sha":null,"homepage":"https://codecov.io","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codecov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-16T09:01:54.000Z","updated_at":"2024-09-01T02:46:19.000Z","dependencies_parsed_at":"2024-11-07T00:35:25.605Z","dependency_job_id":"3fb7186e-3ac3-4662-b8e7-a005205106b9","html_url":"https://github.com/codecov/example-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecov%2Fexample-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecov%2Fexample-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecov%2Fexample-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecov%2Fexample-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codecov","download_url":"https://codeload.github.com/codecov/example-node/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247563942,"owners_count":20958971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["istanbul","javascript","node"],"created_at":"2024-08-01T17:01:06.738Z","updated_at":"2025-04-06T23:18:20.734Z","avatar_url":"https://github.com/codecov.png","language":"JavaScript","readme":"# [Codecov][0] NodeJS / Javascript Example\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-node.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-node?ref=badge_shield)\n\n\n## Guide\n\nYou can install Codecov by adding\n```sh\nnpm install -g codecov\n```\n\n### Travis Setup\n\nAdd the following to your `.travis.yml`:\n\n```yml\nlanguage:\n  node_js\nbefore_install:\n  - npm install -g codecov\nscript:\n  - istanbul cover ./node_modules/mocha/bin/_mocha --reporter lcovonly -- -R spec\n  - codecov\n\n```\n\nThe first script line will change depending on your coverage collecting tool, see below.\n### Produce Coverage Reports\n### [Mocha](http://mochajs.org/) + [Blanket.js](https://github.com/alex-seville/blanket)\n- Install [blanket.js](http://blanketjs.org/)\n- Configure blanket according to [docs](https://github.com/alex-seville/blanket/blob/master/docs/getting_started_node.md).\n- Run your tests with a command like this:\n\n```sh\nNODE_ENV=test YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha \\\n  --require blanket \\\n  --reporter mocha-lcov-reporter\ncodecov\n```\n### [Mocha](http://mochajs.org/) + [JSCoverage](https://github.com/fishbar/jscoverage)\n\nInstrumenting 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.\n\nIn mocha, if you've got your code instrumented for coverage, the command for a travis build would look something like this:\n```sh\nYOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha test -R mocha-lcov-reporter\n```\n\n### [Istanbul](https://istanbul.js.org/)\n\n**With Mocha:**\n\n```sh\nnyc --reporter=lcov mocha \u0026\u0026 codecov\n```\n\n**With Jasmine:**\n\n```sh\nistanbul cover ./node_modules/jasmine/bin/jasmine.js\n```\n\n***With Karma:***\n\nThe `lcov.info` can be used as in other configurations. Some projects experienced better results using `json` output but it is no longer enabled by default. In `karma.config.js` both can be enabled:\n\n```javascript\nmodule.exports = function karmaConfig (config) {\n    config.set({\n        ...\n        reporters: [\n            ...\n            // Reference: https://github.com/karma-runner/karma-coverage\n            // Output code coverage files\n            'coverage'\n        ],\n        // Configure code coverage reporter\n        coverageReporter: {\n            reporters: [\n                // generates ./coverage/lcov.info\n                {type:'lcovonly', subdir: '.'},\n                // generates ./coverage/coverage-final.json\n                {type:'json', subdir: '.'},\n            ]\n        },\n        ...\n    });\n};\n```\n\nIn `package.json` supply either `lcov.info` or `coverage-final.json` to `codecov`:\n\n```javascript\n{\n  \"scripts\": {\n    \"report-coverage\": \"codecov\",\n    ...\n  }\n  ...\n}\n```\n\n### [Nodeunit](https://github.com/caolan/nodeunit) + [JSCoverage](https://github.com/fishbar/jscoverage)\n\nDepend on nodeunit and jscoverage:\n\n```sh\nnpm install nodeunit jscoverage codecov --save-dev\n```\n\nAdd a codecov script to \"scripts\" in your `package.json`:\n\n```javascript\n\"scripts\": {\n  \"test\": \"nodeunit test\",\n  \"codecov\": \"jscoverage lib \u0026\u0026 YOURPACKAGE_COVERAGE=1 nodeunit --reporter=lcov test \u0026\u0026 codecov\"\n}\n```\n\nEnsure your app requires instrumented code when `process.env.YOURPACKAGE_COVERAGE` variable is defined.\n\nRun your tests with a command like this:\n\n```sh\nnpm run codecov\n```\n\n### [GitHub Actions](https://github.com/codecov/codecov-action)\n\n```yaml\n- name: Codecov\n  uses: codecov/codecov-action@v2\n  with:\n    token: ${{ secrets.CODECOV_TOKEN }}\n    flags: unittests\n```\n\n### [Poncho](https://github.com/deepsweet/poncho)\nClient-side JS code coverage using [PhantomJS](https://github.com/ariya/phantomjs), [Mocha](http://mochajs.org/) and [Blanket](https://github.com/alex-seville/blanket):\n- [Configure](http://mochajs.org/#running-mocha-in-the-browser) Mocha for browser\n- [Mark](https://github.com/deepsweet/poncho#usage) target script(s) with `data-cover` html-attribute\n- Run your tests with a command like this:\n\n```sh\n./node_modules/.bin/poncho -R lcov test/test.html \u0026\u0026 codecov\n```\n\n### [Lab](https://github.com/hapijs/lab)\n```sh\nistanbul cover ./node_modules/lab/bin/lab --report lcovonly  -- -l  \u0026\u0026 codecov\n```\n\n### [nyc](https://github.com/bcoe/nyc)\n```javascript\n{\n  \"scripts\": {\n    \"report-coverage\": \"nyc report --reporter=text-lcov \u003e coverage.lcov \u0026\u0026 codecov\",\n    ...\n  }\n  ...\n}\n```\n\n### [Jest](https://facebook.github.io/jest/)\nRun\n```sh\njest --ci --coverage \u0026\u0026 codecov\n```\n\nor you can add it in your package.json:\n```javascript\n\"jest\": {\n  \"coverageDirectory\": \"./coverage/\",\n  \"collectCoverage\": true\n}\n```\nJest will now generate coverage files into `coverage/` and you can run your tests with a command like this:\n```sh\njest \u0026\u0026 codecov\n```\n\n### JSX\nThere have been reports of [gotwarlost/istanbul](https://github.com/gotwarlost/istanbul) not working properly with JSX files, which provide inaccurate coverage results. Please try using [ambitioninc/babel-istanbul](https://github.com/ambitioninc/babel-istanbul).\n\n### [Tape](https://github.com/substack/tape)\n\n```\nistanbul cover node_modules/.bin/tape ./test/*.js\n```\n\nOr simply run:\n\n```\nistanbul cover ./test/*.js\n```\n\nOr add in package.json:\n\n```\n\"test\": \"istanbul cover test/*.js\",\n```\n\nAfter test:\n\n```\ncodecov --token=:token\n```\n\n## Caveats\n#### Private Repo\nRepository tokens are required for (a) all private repos, (b) public repos not using Travis-CI, CircleCI or AppVeyor. Find your repository token at Codecov and provide via `codecov --token=:token` or `export CODECOV_TOKEN=\":token\"`\n\n## Common Pitfalls\n\n### [`mock-fs`](https://github.com/tschaub/mock-fs)\nWhen using `mock-fs` make sure to run `mock.restore()` when your tests are done running, or else the reports wont get generated on the CI.\n\n## Support\n\n### FAQ\n- Q: Is there a TypeScript example?\u003cbr/\u003eA: Yes [codecov/example-typescript](https://github.com/codecov/example-typescript).\n\n1. More documentation at https://docs.codecov.io\n2. Configure codecov through the `codecov.yml`  https://docs.codecov.io/docs/codecov-yaml\n\n[0]: https://codecov.io/\n\nWe are happy to help if you have any questions. Please contact email our Support at [support@codecov.io](mailto:support@codecov.io)\n\n\n## License\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-node.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-node?ref=badge_large)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecov%2Fexample-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodecov%2Fexample-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecov%2Fexample-node/lists"}