|
1 | | -(function (lcovParse, Q, Joi, logger, util, path) { |
| 1 | +(function (lcovParse, Promise, Joi, logger, util, path) { |
2 | 2 | 'use strict'; |
3 | | - var lcovStringValidation = Joi.string().required(), |
4 | | - optionsValidation = Joi.object().keys().optional(); |
| 3 | + |
| 4 | + var lcovStringValidation = Joi.string().required(); |
| 5 | + var optionsValidation = Joi.object().keys().optional(); |
| 6 | + |
5 | 7 | module.exports = { |
6 | 8 | parse: function parseLcov(pathPrefix, lcovString, options) { |
7 | | - logger.debug('Parsing Lcov Data'); |
8 | | - var deferred = Q.defer(); |
9 | | - process.nextTick(function () { |
10 | | - var validLcov = Joi.validate(lcovString, lcovStringValidation), |
11 | | - validOptions = Joi.validate(options, optionsValidation, { |
12 | | - stripUnknown: true |
13 | | - }), |
14 | | - validationError = validLcov.error || validOptions.error; |
| 9 | + return new Promise(function (resolve, reject) { |
| 10 | + logger.debug('Parsing Lcov Data'); |
| 11 | + var validLcov = Joi.validate(lcovString, lcovStringValidation); |
| 12 | + var validOptions = Joi.validate(options, optionsValidation, { |
| 13 | + stripUnknown: true |
| 14 | + }); |
| 15 | + var validationError = validLcov.error || validOptions.error; |
15 | 16 |
|
16 | 17 | if (validationError) { |
17 | 18 | logger.error(validationError); |
18 | | - return deferred.reject(validationError); |
| 19 | + return reject(validationError); |
19 | 20 | } |
20 | 21 |
|
21 | 22 | lcovParse(lcovString, function (err, data) { |
22 | 23 | if (err) { |
23 | 24 | err = new Error(err); |
24 | 25 |
|
25 | 26 | logger.error(err); |
26 | | - return deferred.reject(err); |
| 27 | + return reject(err); |
27 | 28 | } |
28 | 29 |
|
29 | 30 | var result = { |
30 | | - total: 0, |
31 | | - fileReports: [] |
32 | | - }, |
33 | | - totalLines = 0, |
34 | | - totalHits = 0; |
| 31 | + total: 0, |
| 32 | + fileReports: [] |
| 33 | + }; |
| 34 | + var totalLines = 0; |
| 35 | + var totalHits = 0; |
35 | 36 |
|
36 | 37 | //TODO: Convert to reduce function |
37 | 38 | data.forEach(function (stats) { |
|
45 | 46 | totalHits += stats.lines.hit; |
46 | 47 |
|
47 | 48 | // The API uses integers only, so convert accordingly. |
48 | | - console.log("pilas" + stats.lines.hit + '/' + stats.lines.found); |
49 | | - |
50 | 49 | fileStats.total = Math.floor(util.safeDivision(stats.lines.hit, stats.lines.found) * 100); |
51 | 50 |
|
52 | 51 | //TODO: Convert to reduce function |
|
67 | 66 |
|
68 | 67 | logger.debug('Successfully Parsed Lcov Data'); |
69 | 68 |
|
70 | | - deferred.resolve(result); |
| 69 | + resolve(result); |
71 | 70 | }); |
72 | 71 | }); |
73 | | - return deferred.promise; |
74 | 72 | } |
75 | 73 | }; |
76 | | -}(require('lcov-parse'), require('q'), require('joi'), require('../logger')(), require('../util'), require('path'))); |
| 74 | +}(require('lcov-parse'), require('bluebird'), require('joi'), require('../logger')(), require('../util'), require('path'))); |
0 commit comments