FormidableLabs/istanbul

Name: istanbul

Owner: Formidable

Description: Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.

Created: 2014-10-10 22:05:16.0

Updated: 2014-10-10 17:15:48.0

Pushed: 2014-10-23 18:20:15.0

Homepage: null

Size: 2673

Language: null

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Istanbul - a JS code coverage tool written in JS

Build Status Dependency Status Coverage Status

NPM

Features
Use cases

Supports the following use cases and more

Getting started
$ npm install -g istanbul

The best way to see it in action is to run node unit tests. Say you have a test script test.js that runs all tests for your node project without coverage.

Simply:

$ cd /path/to/your/source/root
$ istanbul cover test.js

and this should produce a coverage.json, lcov.info and lcov-report/*html under ./coverage

Sample of code coverage reports produced by this tool (for this tool!):

HTML reports

Configuring

Drop a .istanbul.yml file at the top of the source tree to configure istanbul. istanbul help config tells you more about the config file format.

The command line
$ istanbul help

gives you detailed help on all commands.

e: istanbul help config | <command>

fig` provides help with istanbul configuration

lable commands are:

  check-coverage
          checks overall coverage against thresholds from coverage JSON
          files. Exits 1 if thresholds are not met, 0 otherwise


  cover   transparently adds coverage information to a node command. Saves
          coverage.json and reports at the end of execution


  help    shows help


  instrument
          instruments a file or a directory tree and writes the
          instrumented code to the desired output location


  report  writes reports for coverage JSON objects produced in a previous
          run


  test    cover a node command only when npm_config_coverage is set. Use in
          an `npm test` script for conditional coverage


and names can be abbreviated as long as the abbreviation is unambiguous
The cover command
$ istanbul cover my-test-script.js -- my test args
# note the -- between the command name and the arguments to be passed

The cover command can be used to get a coverage object and reports for any arbitrary node script. By default, coverage information is written under ./coverage - this can be changed using command-line options.

The cover command can also be passed an optional --handle-sigint flag to enable writing reports when a user triggers a manual SIGINT of the process that is being covered. This can be useful when you are generating coverage for a long lived process.

The test command

The test command has almost the same behavior as the cover command, except that it skips coverage unless the npm_config_coverage environment variable is set.

This command is deprecated since the latest versions of npm do not seem to set the npm_config_coverage variable.

The instrument command

Instruments a single JS file or an entire directory tree and produces an output directory tree with instrumented code. This should not be required for running node unit tests but is useful for tests to be run on the browser.

The report command

Writes reports using coverage*.json files as the source of coverage information. Reports are available in multiple formats and can be individually configured using the istanbul config file. See istanbul help report for more details.

The check-coverage command

Checks the coverage of statements, functions, branches, and lines against the provided thresholds. Positive thresholds are taken to be the minimum percentage required and negative numbers are taken to be the number of uncovered entities allowed.

Ignoring code for coverage

See ignoring-code-for-coverage.md for the spec.

API

All the features of istanbul can be accessed as a library.

Instrument code
var instrumenter = new require('istanbul').Instrumenter();

var generatedCode = instrumenter.instrumentSync('function meaningOfLife() { return 42; }',
    'filename.js');
Generate reports given a bunch of coverage JSON objects
var istanbul = require('istanbul'), 
    collector = new istanbul.Collector(),
    reporter = new istanbul.Reporter(),
    sync = false;

collector.add(obj1);
collector.add(obj2); //etc.

reporter.add('text');
reporter.addAll([ 'lcov', 'clover' ]);
reporter.write(collector, sync, function () {
    console.log('All reports generated');
});

For the gory details consult the public API

License

istanbul is licensed under the BSD License.

Third-party libraries

The following third-party libraries are used by this module:

Inspired by
Shout out to
Why the funky name?

Since all the good ones are taken. Comes from the loose association of ideas across coverage, carpet-area coverage, the country that makes good carpets and so on…


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.