Code coverage report for lib/process.js

Statements: 96.3% (26 / 27)      Branches: 82.14% (23 / 28)      Functions: 100% (5 / 5)      Lines: 96.3% (26 / 27)     

All files » lib/ » process.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 561   1 3     3 29 29   29 8         3 1   2 5 2   3 3 3 67 67   67 10               3               3   3 3 1   3      
var YUITest = require('yuitest');
 
module.exports = function(results, type) {
    var data = {},
        str = '',
        handle = function(r) {
            Object.keys(r).forEach(function(key) {
                Eif (!data[key]) {
                    data[key] = r[key];
                }
                if (data[key] && (typeof data[key] === 'number')) {
                    data[key] += r[key];
                }
            });
        };
 
    if (Array.isArray(results) && results.length === 1) {
        handle(results[0]);
    } else {
        results.forEach(function(d, index) {
            if (index === 0) {
                handle(d);
            } else {
                var name = d.name;
                data[name] = data[name] || {};
                Object.keys(d).forEach(function(key) {
                    Eif (!data[name][key]) {
                        data[name][key] = d[key];
                    }
                    if (data[name][key] && (typeof data[name][key] === 'number')) {
                        data[name][key] += d[key];
                    }
                });
            }
        });
    }
 
    //Fixes #9 - YUITest knows nothing about Istanbul data, so we need to remove it first
    Iif (data.coverage && data.coverageType && data.coverageType === 'istanbul' && type !== 'JSON') {
        delete data.coverage;
    }
 
    /*
    I know this is bad, but YUITest.TestRunner doesn't allow
    me to add results in a public way, so I have to "work around" it :)
    */
    YUITest.TestRunner._lastResults = data;
 
    str = YUITest.TestRunner.getResults(YUITest.TestFormat[type]);
    if (type === 'JSON') {
        str = JSON.stringify(JSON.parse(str), null, 4) + '\n';
    }
    return str;
};