coveralls-api
Version:
API client for coveralls.io
80 lines (64 loc) • 2.87 kB
JavaScript
;
exports.__esModule = true;
exports.getSourceFiles = getSourceFiles;
var _path = require("path");
var _md = _interopRequireDefault(require("md5"));
var _readFileSafe = require("read-file-safe");
var _readLcovSafe = require("read-lcov-safe");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function getCoverage(details, length) {
return details.reduce(function (coverage, _ref) {
var line = _ref.line,
hit = _ref.hit;
coverage[line - 1] = hit;
return coverage;
}, new Array(length).fill(null));
}
function getBranches(details) {
return details.reduce(function (branches, item) {
branches.push(item.line);
branches.push(item.block);
branches.push(item.branch);
branches.push(item.taken);
return branches;
}, []);
}
function getSourceFiles(_x) {
return _getSourceFiles.apply(this, arguments);
}
function _getSourceFiles() {
_getSourceFiles = _asyncToGenerator(function* (lcov_path) {
return (0, _readLcovSafe.readLCOV)(lcov_path).then( /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(function* (records) {
return Promise.all(records.map( /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator(function* (record) {
var path = (0, _path.resolve)(process.cwd(), record.file);
return (0, _readFileSafe.readFile)(path).then(function (source) {
if (source === void 0) {
source = "";
}
var _source$split = source.split("\n"),
length = _source$split.length;
return {
name: record.file,
source_digest: (0, _md["default"])(source),
coverage: getCoverage(record.lines.details, length),
branches: getBranches(record.branches.details),
source: source
};
});
});
return function (_x3) {
return _ref3.apply(this, arguments);
};
}()));
});
return function (_x2) {
return _ref2.apply(this, arguments);
};
}());
});
return _getSourceFiles.apply(this, arguments);
}