Giter VIP home page Giter VIP logo

node-coveralls's Introduction

#node-coveralls

Build Status Coverage Status Codeship Build Status Build Status

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.

Supported CI services: travis-ci, codeship, circle-ci, jenkins

##Installation: Add the latest version of coveralls to your package.json:

npm install coveralls --save 

If you're using mocha, add mocha-lcov-reporter to your package.json:

npm install mocha-lcov-reporter --save 

##Usage:

This script ( bin/coveralls.js ) can take standard input from any tool that emits the lcov data format (including mocha's LCov reporter) and send it to coveralls.io to report your code coverage there.

Once your app is instrumented for coverage, and building, you need to pipe the lcov output to ./node_modules/coveralls/bin/coveralls.js.

This library currently supports travis-ci with no extra effort beyond that, but if you're using a different build system, there are a few environment variables that are necessary:

  • COVERALLS_SERVICE_NAME (the name of your build system)
  • COVERALLS_REPO_TOKEN (the secret repo token from coveralls.io)

There are optional environment variables for other build systems as well:

  • COVERALLS_SERVICE_JOB_ID (an id that uniquely identifies the build job)
  • 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.)
  • Install blanket.js
  • Configure blanket according to docs.
  • Run your tests with a command like this:
NODE_ENV=test YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha \
  --require blanket \
  --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js

Instrumenting your app for coverage is probably harder than it needs to be (read here or here), but that's also a necessary step.

In mocha, if you've got your code instrumented for coverage, the command for a travis build would look something like this:

YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha test -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js

Check out an example Makefile from one of my projects for an example, especially the test-coveralls build target. Note: Travis 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).

istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage

Depend on nodeunit, jscoverage and coveralls:

npm install nodeunit jscoverage coveralls --save-dev

Add a coveralls script to "scripts" in your package.json:

"scripts": {
  "test": "nodeunit test",
  "coveralls": "jscoverage lib && YOURPACKAGE_COVERAGE=1 nodeunit --reporter=lcov test | coveralls"
}

Ensure your app requires instrumented code when process.env.YOURPACKAGE_COVERAGE variable is defined.

Run your tests with a command like this:

npm run coveralls

For detailed instructions on requiring instrumented code, running on Travis and submitting to coveralls see this guide.

Client-side JS code coverage using PhantomJS, Mocha and Blanket:

  • Configure Mocha for browser
  • Mark target script(s) with data-cover html-attribute
  • Run your tests with a command like this:
./node_modules/.bin/poncho -R lcov test/test.html | ./node_modules/coveralls/bin/coveralls.js

Running locally

If you're running locally, you must have a .coveralls.yml file, as documented in their documentation, with your repo_token in it; or, you must provide a COVERALLS_REPO_TOKEN environment-variable on the command-line.

If 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.

Contributing

I 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 afterall!).

I 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.

node-coveralls's People

Contributors

cainus avatar gabehayes avatar tdd avatar gerarde avatar mattjmorrison avatar alanshaw avatar swatinem avatar ilanbiala avatar elliottcable avatar flatheadmill avatar jonathankingston avatar paazmaya avatar paroga avatar deepak1556 avatar jaubourg avatar

Watchers

Esco Obong avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.