Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
code coverage in native javascript
tree: d15e51f0a9

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example/top
test
README.markdown
index.js

README.markdown

bunker

Bunker is a module to calculate code coverage using native javascript burrito AST trickery.

code coverage

examples

top

example/top/run.js:

var bunker = require('../../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/src.js', 'utf8');

var counts = {};

var b = bunker(src);
b.on('node', function (node) {
    if (!counts[node.range]) {
        counts[node.range] = { times : 0, node : node };
    }
    counts[node.range].times ++;
});

b.run({
    setInterval : setInterval,
    clearInterval : clearInterval,
    end : function () {
        Object.keys(counts)
            .sort(function (a, b) {
                return counts[b].times - counts[a].times
            })
            .forEach(function (key) {
                var count = counts[key];
                console.log(
                    count.times + ' : ' + count.node.source()
                );
            })
        ;
    }
});

example/top/src.js:

function boop () {
    for (var i = 0; i < 30; i++) {
        nop();
    }
}

function nop () {
    return undefined;
}

var times = 0;
var iv = setInterval(function () {
    if (++times === 10) {
        clearInterval(iv);
        end();
    }
    else boop()
}, 100);

output:

$ node example/top/run.js 
279 : i<30
270 : nop()
270 : nop();
270 : i++
18 : boop();
10 : ++times
10 : ++times===10
1 : setInterval(function(){if(++times===10){clearInterval(iv);end()}else boop()},100)
1 : clearInterval(iv);
1 : clearInterval(iv)
1 : end();
1 : end()

methods

var bunker = require('bunker');

var b = bunker(src)

Create a new bunker code coverageifier with some source src.

The bunker object b is an EventEmitter that emits 'node' events with two parameters:

b.include(src)

Include some source into the bunker.

b.compile()

Return the source wrapped with burrito.

b.run(context={})

Run the source using vm.runInNewContext() with some context.

Something went wrong with that request. Please try again.