Code coverage report for lib/tasks/coverage.js

Statements: 100% (18 / 18)      Branches: 100% (8 / 8)      Functions: 100% (3 / 3)      Lines: 100% (18 / 18)     

All files » lib/tasks/ » coverage.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          1       1 18   18   18   18   18 2 2 1   1 1       16 16     16 16 1   15          
/*
Copyright (c) 2012, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://yuilibrary.com/license/
*/
var ycoverage = require('yuitest-coverage'),
    istanbul = require('istanbul'),
    log = require('../log');
 
exports.coverage = function (options, blob, done) {
    options = options || {}; //Not needed here??
 
    var type = options.type,
        inst;
    delete options.type;
 
    log.info(type + ' providing coverage');
 
    if (type === 'yuitest') {
        ycoverage.cover(blob.result, options, function (err, data) {
            if (err) {
                done(err);
            } else {
                data = data.replace(/\r\n/g, '\n');
                done(null, new blob.constructor(data, blob));
            }
        });
    } else {
        log.log('instrumenting with istanbul');
        inst = new istanbul.Instrumenter({
            embedSource: true
        });
        inst.instrument(blob.result, options.name, function (err, data) {
            if (err) {
                done(err);
            } else {
                done(null, new blob.constructor(data, blob));
            }
        });
    }
};