node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Runforcover is a require-hook library that uses node-bunker to provide code coverage data for your unit test library, whatever it might be.


var runforcover = require('runforcover');

var coverage = runforcover.cover([RegExp | path]);

Attach runforcover to the global require object and patch require.extensions['.js'] to provide coverage metadata for all files required after this point. Returns a function object that can be called to obtain a object keying files to CoverageData objects, with a method for releasing control back to vanilla require. Usage:

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 


new BSD.