Code coverage report for lib/index.js

Statements: 100% (60 / 60)      Branches: 94.44% (51 / 54)      Functions: 100% (11 / 11)      Lines: 100% (60 / 60)     

All files » lib/ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 1341 1   1 1   1   1               27 27 27 27 71           1   11 1           513 506   7         36 36 36 36 2 2 1     36 7   36     2     59     34                 34 23       34 5     34 2 2 193       34   34 14 7   7 98 98 44 396 4 36 4 4       392 16 16                 34 10         5       1 11 11      
var color = require('ansi-color').set;
var cover = require('./coverage');
//Moved to another file so it's easy to edit on windows.
var chars = require('./chars');
var timethat = require('timethat');
 
var log = require('./log');
 
var good = chars.good,
    bad = chars.bad,
    i,
    mods,
    hasColor = process.stdout.isTTY,
    path = require('path'),
    fs = require('fs'),
    printFail = function(name, message) {
        message = message.replace(/%5C/g, '\\');
        log.log('    ' + mods.color(name, 'red+bold'));
        var m = message.split('\n');
        m.forEach(function(line) {
            log.log('       ' + mods.color(line, 'red+bold'));
        });
    };
 
 
 
mods = {
    init: function(options) {
        if (options.color === false || !process.stdout.isTTY) {
            hasColor = false;
        }
    },
    exists: fs.exists || path.exists,
    existsSync: fs.existsSync || path.existsSync,
    color: function (str, code) {
        if (!hasColor) {
            return str;
        }
        return color(str, code);
    },
    good: good,
    bad: bad,
    canPrint: function(options, json) {
        json = json || {};
        options = options || {};
        var p = true;
        if (options.quiet) {
            p = false;
            if (json.failed) {
                p = true;
            }
        }
        if (options.silent) {
            p = false;
        }
        return p;
    },
    error: function(str) {
        log.error(mods.color(str, 'red'));
    },
    log: function(str) {
        log.log(mods.color(str, 'bold+blue'));
    },
    status: function(json, start, end) {
        var str = (json.failed ? mods.color(bad, 'bold+red') : mods.color(good, 'bold+green')) +
            ' ' + mods.color('[' + json.name + ']:', (json.failed ? 'red' : 'blue') + '+bold') +
            ' Passed: ' + (json.passed ? mods.color(String(json.passed), 'green+bold') : json.passed) +
            ' Failed: ' + (json.failed ? mods.color(String(json.failed), 'red+bold') : json.failed) +
            ' Total: ' +  json.total +
            mods.color(' (ignored ' + json.ignored + ')', 'white'),
            s = (new Date()).getTime(),
            e = s + json.duration;
 
        if (json.duration) {
            str += ' (' + timethat.calc(s, e) + ')';
        }
 
 
        if (json.coverage) {
            str += cover.status(json.coverage);
        }
 
        if (json.consoleInfo && json.consoleInfo.length) {
            str += '\n';
            json.consoleInfo.forEach(function(line) {
                str += '    ' + mods.color(line.type + ': ', 'white') + line['arguments'].join(', ') + '\n';
            });
        }
 
        log.log(str);
 
        if (json.failed) {
            if (json.error) {
                printFail('Javascript Error', json.error);
            } else {
                Object.keys(json).forEach(function(key) {
                    var i, t, res;
                    if (typeof json[key] === 'object') {
                        for (i in json[key]) {
                            if (json[key][i].failed) {
                                for (t in json[key][i]) {
                                    if (json[key][i][t].result === 'fail') {
                                        res = json[key][i][t];
                                        printFail(res.name, res.message);
                                    }
                                }
                            } else {
                                if (json[key][i].result === 'fail') {
                                    res = json[key][i];
                                    printFail(res.name, res.message);
                                }
                            }
                        }
                    }
                });
            }
        }
 
        if (start && end) {
            exports.log('  [Grover Execution Timer] ' + timethat.calc(start, end));
        }
 
    },
    exit: function(code) {
        process.exit(code);
    }
};
 
for (i in mods) {
    Eif (mods.hasOwnProperty(i)) {
        exports[i] = mods[i];
    }
}