coverage.js
function populateCoverage(cov) {
    cov.LOC =
    cov.SLOC =
    cov.totalFiles =
    cov.totalHits =
    cov.totalMisses =
    cov.coverage = 0;
    for (var name in cov) {
        var file = cov[name];
        if (Array.isArray(file)) {
            // Stats
            ++cov.totalFiles;
            cov.totalHits += file.totalHits = coverage(file, true);
            cov.totalMisses += file.totalMisses = coverage(file, false);
            file.totalLines = file.totalHits + file.totalMisses;
            cov.SLOC += file.SLOC = file.totalLines;
            if (!file.source) file.source = [];
            cov.LOC += file.LOC = file.source.length;
            file.coverage = (file.totalHits / file.totalLines) * 100;
            // Source
            var width = file.source.length.toString().length;
            file.source = file.source.map(function(line, i){
                ++i;
                var hits = file[i] === 0 ? 0 : (file[i] || ' ');
                if (hits === 0) {
                    hits = '\x1b[31m' + hits + '\x1b[0m';
                    line = '\x1b[41m' + line + '\x1b[0m';
                } else {
                    hits = '\x1b[32m' + hits + '\x1b[0m';
                }
                return '\n     ' + lpad(i, width) + ' | ' + hits + ' | ' + line;
            }).join('');
        }
    }
    cov.coverage = (cov.totalHits / cov.SLOC) * 100;
}
function populateCoverage(cov) {
    cov.LOC =
    cov.SLOC =
    cov.totalFiles =
    cov.totalHits =
    cov.totalMisses =
    cov.coverage = 0;
    for (var name in cov) {
        var file = cov[name];
        if (Array.isArray(file)) {
            // Stats
            ++cov.totalFiles;
            cov.totalHits += file.totalHits = coverage(file, true);
            cov.totalMisses += file.totalMisses = coverage(file, false);
            file.totalLines = file.totalHits + file.totalMisses;
            cov.SLOC += file.SLOC = file.totalLines;
            if (!file.source) file.source = [];
            cov.LOC += file.LOC = file.source.length;
            file.coverage = (file.totalHits / file.totalLines) * 100;
            // Source
            var width = file.source.length.toString().length;
            file.source = file.source.map(function(line, i){
                ++i;
                var hits = file[i] === 0 ? 0 : (file[i] || ' ');
                if (hits === 0) {
                    hits = '\x1b[31m' + hits + '\x1b[0m';
                    line = '\x1b[41m' + line + '\x1b[0m';
                } else {
                    hits = '\x1b[32m' + hits + '\x1b[0m';
                }
                return '\n     ' + lpad(i, width) + ' | ' + hits + ' | ' + line;
            }).join('');
        }
    }
    cov.coverage = (cov.totalHits / cov.SLOC) * 100;
}
function populateCoverage ( cov ) { cov . LOC = cov . SLOC = cov . totalFiles = cov . totalHits = cov . totalMisses = cov . coverage = 0 ; for ( var name in cov ) { var file = cov [ name ] ; if ( Array . isArray ( file ) ) { // Stats ++ cov . totalFiles ; cov . totalHits += file . totalHits = coverage ( file , true ) ; cov . totalMisses += file . totalMisses = coverage ( file , false ) ; file . totalLines = file . totalHits + file . totalMisses ; cov . SLOC += file . SLOC = file . totalLines ; if ( ! file . source ) file . source = [ ] ; cov . LOC += file . LOC = file . source . length ; file . coverage = ( file . totalHits / file . totalLines ) * 100 ; // Source var width = file . source . length . toString ( ) . length ; file . source = file . source . map ( function ( line , i ) { ++ i ; var hits = file [ i ] === 0 ? 0 : ( file [ i ] || ' ' ) ; if ( hits === 0 ) { hits = '\x1b[31m' + hits + '\x1b[0m' ; line = '\x1b[41m' + line + '\x1b[0m' ; } else { hits = '\x1b[32m' + hits + '\x1b[0m' ; } return '\n     ' + lpad ( i , width ) + ' | ' + hits + ' | ' + line ; } ) . join ( '' ) ; } } cov . coverage = ( cov . totalHits / cov . SLOC ) * 100 ; }
Populate code coverage data.
@param  {Object} cov
Populate code coverage data .