Native JavaScript Code Coverage
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Fixing 'filename' for summary data. Aug 26, 2013
contrib Update esprima Dec 4, 2012
reporters Escape source code before outputting to HTML. Apr 9, 2012
resources Add better formatting for HTML Nov 28, 2011
templates Show overall coverage in HTML reporter Jul 11, 2012
test Add proper handling for return statements and ternary expressions Mar 1, 2012
utils Initial commit for node-cover Nov 26, 2011
README.markdown Update README.markdown Apr 17, 2015
coverage_store.js No more contexts - instrument the files directly (a la jscoverage) Feb 28, 2012
index.js Make it work on Windows! Mar 25, 2012
package.json Increment version Aug 23, 2013


Cover - Native JavaScript Code Coverage

Cover gives you the ability to collect code-coverage for your projects, using whatever unit test framework you want, and all using native JavaScript. It also comes bundled with pre-defined reporters, such as HTML and CLI output, so you can easily see where you are missing coverage.

Standing on the shoulders of giants

I would be amiss to not mention that the hard work in this library was by Chris Dickinson with his work on runforcover. In reality, Cover is a fork of runforcover, fixing some of the issues and making it more usable.

The original version of Cover used substack's excellent bunker library, but it has recently been moved to using esprima and a new code homegrown instrumentation library.

Known Issues

There are currently a few known issues that I am working on:

  1. If you use 'global' to pass state between modules (mocha does this, for example), then you might run into issues. Cover runs modules as if they were executed with NODE_MODULE_CONTEXTS was set.

  2. If you start new node processes, Cover won't work with those, as it instruments by hooking into require.


Using Cover is simple. Simply install it globally:

npm install cover -g

And then, run it

cover run mytests.js

Want to pass some arguments to your test? No problem (note the --):

cover run mytests.js -- --arg1 --arg2=foo

Once you've run your tests, it will create a directory with coverage data in it. If you want to see the coverage report, simply run:

cover report

which will output the report to the CLI. Want to get an HTML report?

cover report html

This will create a cover_html directory with the coverage information.


Cover reads from a .coverrc file in your project directory, and it comes with sensible defaults. Here are the defaults that it uses:

    "formatter": "cli",
    "ignore": ".coverignore",
    "prefix": "coveragefile_",              // Prefix for coverage data files
    "dataDirectory": ".coverage_data",      // Directory to put coverage files in
    "debugDirectory": ".coverage_debug",    // Directory to put instrumented files in
    "modules": false,                       // Whether or not to cover node_modules directory
    // Formatter-specific info
    "html" : {
        "directory": "cover_html",          // Directory to write HTML files too
        "generateIndex": true               // Whether to generate an index.html file
    "json": {

You can also specify which files to ignore using .coverignore. Here is the one used for Cover itself:


You can specify both files and directories in the .coverignore file.

If you have a custom path for your configuration files, you can specify this on the command line:

cover --config path/to/config --ignore path/to/ignore run myfile.js