javascript code coverage tools

shows what lines of a program have been executed
and which have been missed
this information is useful for constructing comprehensive test suites
code coverage statistics are collected while JS is executed in a browser

Find line and branch coverage
Currently integrates with jasmine
Is a Java Project
Requires you to run code with Rhino
uses Rhino debugger interface to hook into loading source files
Format can be exported to Cobertura style XML or HTML report

Chrome Extension
Line by Line JS Code Coverage statistics
Reports which statements from internal/external scripts have been executed
Counts how many times
In browser doesn’t work
It doesn’t check source, but execution

List all scripts Firefox knows about (included in HTML)
Executes in browser?

written in javascript
uses uglifyjs parser/mangler/compressor/beautifier
for js programs executed in node
proxy to execute JS in browser in the works

uses node-bunker
provides code coverage data for your unit test library (whatever that may be)

var runforcover = require('runforcover');
var coverage = runforcover.cover(/.*/g);
coverage(function(coverageData) {
    // coverageData is an object keyed by filename.
    var stats = coverageData['/full/path/to/file.js'].stats()

    // the percentage of lines run versus total lines in file

    // the number of missing lines

    // the number of lines run (seen)

    // an array of line objects representing 'missed' lines

    stats.lines.forEach(function(line) {
	// the line number of the line:

	// returns a string containing the source data for the line:

    // return control back to the original require function

fork of runforcover
uses esprima instead of bunker
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.
If you start new node processes, Cover won’t work with those, as it instruments by hooking into require.

See also this blog post:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s