javascript code coverage tools

http://siliconforks.com/jscoverage/

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

http://jescov.olabini.com/

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

http://code.google.com/p/script-cover/

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

http://hrtimer.mozdev.org/

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

http://coveraje.github.com/

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

https://github.com/chrisdickinson/node-runforcover

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
    console.log(stats.percentage);

    // the number of missing lines
    console.log(stats.missing);

    // the number of lines run (seen)
    console.log(stats.seen);

    // an array of line objects representing 'missed' lines
    stats.lines;

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

	// returns a string containing the source data for the line:
	console.log(line.source());   
    }); 

    // return control back to the original require function
    coverage.release(); 
});

https://github.com/itay/node-cover.git

fork of runforcover
bugfixes
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:

http://ariya.ofilabs.com/2012/03/javascript-code-coverage-and-esprima.html

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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