Node Codacy Coverage
Credits to David for creating this!
Codacy support for Node.js. Get coverage reporting and code analysis for Node.js from Codacy.
Installation
Add the latest version of codacy-coverage
to your package.json:
npm install codacy-coverage --save
If you're using mocha, add mocha-lcov-reporter
to your package.json:
npm install mocha-lcov-reporter --save
Enterprise
To send coverage in the enterprise version you should specify your Codacy installation URL:
codacy-coverage -e <YOUR-CODACY-ENTERPRISE-URL>:16006
Usage
This cli can take standard input from any tool that emits the lcov data format (including mocha's LCov reporter) and send it to Codacy to report your code coverage there.
Once your app is instrumented for coverage, and building, you need to pipe the lcov output to codacy-coverage
.
You'll need to provide the Report token from Codacy via an environment variable:
- CODACY_PROJECT_TOKEN (the secret repo token from Codacy.com)
Note: You should keep your API token well protected, as it grants owner permissions to your projects.
- Install blanket.js
- Configure blanket according to docs.
- Add test with coverage step to your package.json:
"scripts": {
"test-with-coverage": "NODE_ENV=test YOURPACKAGE_COVERAGE=1 mocha --require blanket --reporter mocha-lcov-reporter | codacy-coverage"
}
npm run test-with-coverage
Instrumenting your app for coverage is probably harder than it needs to be (read here), but that's also a necessary step.
- Add test with coverage step to your package.json:
"scripts": {
"test-with-coverage": "YOURPACKAGE_COVERAGE=1 mocha test -R mocha-lcov-reporter | codacy-coverage"
}
npm run test-with-coverage
With Mocha
- Add test with coverage step to your package.json:
"scripts": {
"test-with-coverage": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | codacy-coverage && rm -rf ./coverage"
}
npm run test-with-coverage
With Jasmine
- Add test with coverage step to your package.json:
"scripts": {
"test-with-coverage": "istanbul cover jasmine-node --captureExceptions spec/ && cat ./coverage/lcov.info | codacy-coverage && rm -rf ./coverage"
}
npm run test-with-coverage
Client-side JS code coverage using PhantomJS, Mocha and Blanket:
- Configure Mocha for browser
- Mark target script(s) with
data-cover
html-attribute - Add test with coverage step to your package.json:
"scripts": {
"test-with-coverage": "poncho -R lcov test/test.html | codacy-coverage"
}
npm run test-with-coverage
- Add test with coverage step to your package.json:
"scripts": {
"test-with-coverage": "jest --coverage && cat ./coverage/lcov.info | codacy-coverage"
}
npm run test-with-coverage
Account Token
To send coverage using your account/api token you can follow the following steps.
- Add test with coverage step to your package.json:
"scripts": {
"test-with-coverage": "cat ./coverage/lcov.info | codacy-coverage --accountToken <account-token> --username <username> --projectName <project-name>"
}
npm run test-with-coverage
As an alternative you can also export CODACY_ACCOUNT_TOKEN
instead of passing --accountToken <account-token>
to the CLI.
Force custom language (e.g. Typescript, Coffeescript, C, ...)
- Pass an extra parameter to the codacy-coverage reporter
--language typescript
or --language coffeescript
. - If you have multiple languages you need to invoke the reporter for each of them.
Troubleshooting
Path Problems
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:
"scripts": {
"test-with-coverage": "cat ./coverage/lcov.info | codacy-coverage -p ."
}
Enterprise Coverage
To send coverage in the enterprise version you should specify your Codacy installation URL followed by the port 16006 using the -e option, example:
"scripts": {
"test-with-coverage": "cat ./coverage/lcov.info | codacy-coverage -e <YOUR-CODACY-ENTERPRISE-URL>:16006"
}
License
MIT
What is Codacy
Codacy 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.
Among Codacy’s features
- Identify new Static Analysis issues
- Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
- Auto-comments on Commits and Pull Requests
- Integrations with Slack, HipChat, Jira, YouTrack
- Track issues Code Style, Security, Error Proneness, Performance, Unused Code and other categories
Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.
Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.
Free for Open Source
Codacy is free for Open Source projects.