Skip to content

Commit b08e565

Browse files
committed
v0.3.0
1 parent c8307bb commit b08e565

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

lib/index.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
"use strict";
22

3+
var fs = require("fs");
34
var Promise = require("bluebird");
45
var lcov_parse = require("lcov-parse");
56
var _ = require("lodash");
67
var vile = require("vile");
8+
var fs_stat = Promise.promisify(fs.stat);
9+
10+
var log = vile.logger.create("coverage");
711

812
var DEFAULT_COV_DIR = "coverage";
913

1014
var total_cov = function total_cov(lines) {
11-
return !lines ? 0 : lines.length <= 0 ? 100 : _.reduce(lines, function (count, item) {
15+
return _.isEmpty(lines) ? 0 : _.reduce(lines, function (count, item) {
1216
return item.hit > 0 ? count + 1 : count;
1317
}, 0) / lines.length * 100;
1418
};
@@ -35,29 +39,42 @@ var possible_lcov_file = function possible_lcov_file(target) {
3539
var parse_lcov_file_into_issues = function parse_lcov_file_into_issues(lcov_path) {
3640
return new Promise(function (resolve, reject) {
3741
lcov_parse(lcov_path, function (err, lcov) {
38-
if (err) reject(err);else resolve(lcov_into_issues(lcov));
42+
if (err) log.warn(err);
43+
resolve(lcov_into_issues(lcov));
3944
});
4045
});
4146
};
4247

48+
var warn_and_resolve = function warn_and_resolve(lcov_path) {
49+
log.warn("can't find path: \"" + lcov_path + "\"");
50+
return Promise.resolve([]);
51+
};
52+
4353
var detect_lcov_into_issues = function detect_lcov_into_issues() {
44-
return vile.promise_each(DEFAULT_COV_DIR, function (target, is_dir) {
54+
var dirpath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_COV_DIR;
55+
return fs.existsSync(dirpath) ? vile.promise_each(dirpath, function (target, is_dir) {
4556
return is_dir || possible_lcov_file(target);
4657
}, function (file) {
47-
return parse_lcov_file_into_issue(file);
48-
}, { read_data: false });
58+
return parse_lcov_file_into_issues(file);
59+
}, { read_data: false }) : warn_and_resolve(dirpath);
60+
};
61+
62+
var lcov_paths_into_issues = function lcov_paths_into_issues(lcov_path) {
63+
return fs.existsSync(lcov_path) ? fs_stat(lcov_path).then(function (stats) {
64+
return stats.isDirectory() ? detect_lcov_into_issues(lcov_path) : parse_lcov_file_into_issues(lcov_path);
65+
}) : warn_and_resolve(lcov_path);
4966
};
5067

5168
var report_cov = function report_cov(plugin_config) {
52-
var lcov_paths = _.get(plugin_config, "config.path");
69+
var lcov_paths = _.get(plugin_config, "config.paths");
5370

54-
if (_.isEmpty(lcov_paths)) {
55-
return detect_lcov_into_issues();
56-
} else {
57-
return Promise.map(_.concat([], lcov_paths), function (lcov_path) {
58-
return detect_lcov_into_issues(lcov_path);
59-
});
60-
}
71+
return (_.isEmpty(lcov_paths) ? detect_lcov_into_issues() : Promise.map(_.concat([], lcov_paths), lcov_paths_into_issues)).then(function (issues) {
72+
var flat_issues = _.flatten(issues);
73+
if (_.isEmpty(flat_issues)) {
74+
log.warn("no coverage data was found");
75+
}
76+
return flat_issues;
77+
});
6178
};
6279

6380
module.exports = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vile-coverage",
3-
"version": "0.2.17",
3+
"version": "0.3.0",
44
"description": "Track your project's test coverage.",
55
"main": "lib/index.js",
66
"files": [

0 commit comments

Comments
 (0)