Name: js-handler/node_modules/nodeunit/lib/reporters/lcov.js
| 1: | /** |
| 2: | * Module dependencies |
| 3: | */ |
| 4: | |
| 5: | var nodeunit = require('../nodeunit'), |
| 6: | path = require('path'); |
| 7: | |
| 8: | /** |
| 9: | * Reporter info string |
| 10: | */ |
| 11: | |
| 12: | exports.info = 'The LCOV reporter reads JS files instrumented by JSCoverage (http://siliconforks.com/jscoverage/) and outputs coverage data in the LCOV format (http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php)'; |
| 13: | |
| 14: | /** |
| 15: | * Run all tests within each module, reporting the results to the command-line. |
| 16: | * |
| 17: | * @param {Array} files |
| 18: | * @api public |
| 19: | */ |
| 20: | |
| 21: | exports.run = function (files) { |
| 22: | |
| 23: | var paths = files.map(function (p) { |
| 24: | return path.join(process.cwd(), p); |
| 25: | }); |
| 26: | |
| 27: | nodeunit.runFiles(paths, { |
| 28: | done: function () { |
| 29: | var cov = (global || window)._$jscoverage || {}; |
| 30: | |
| 31: | Object.keys(cov).forEach(function (filename) { |
| 32: | var data = cov[filename]; |
| 33: | reportFile(filename, data); |
| 34: | }); |
| 35: | } |
| 36: | }); |
| 37: | }; |
| 38: | |
| 39: | function reportFile(filename, data) { |
| 40: | console.log('SF:' + filename); |
| 41: | |
| 42: | data.source.forEach(function(line, num) { |
| 43: | // increase the line number, as JS arrays are zero-based |
| 44: | num++; |
| 45: | |
| 46: | if (data[num] !== undefined) { |
| 47: | console.log('DA:' + num + ',' + data[num]); |
| 48: | } |
| 49: | }); |
| 50: | |
| 51: | console.log('end_of_record'); |
| 52: | } |
