Skip to content

Commit

Permalink
feat: once 100% line coverage is achieved, missing branch coverage is…
Browse files Browse the repository at this point in the history
… now shown in text report (#45)
  • Loading branch information
bcoe committed Apr 29, 2017
1 parent c623f38 commit 8a809f8
Show file tree
Hide file tree
Showing 7 changed files with 4,871 additions and 3 deletions.
27 changes: 26 additions & 1 deletion packages/istanbul-lib-report/lib/file-writer.js
Expand Up @@ -84,8 +84,15 @@ function ConsoleWriter() {
}
util.inherits(ConsoleWriter, ContentWriter);

// allow stdout to be captured for tests.
var capture = false;
var output = '';
ConsoleWriter.prototype.write = function (str) {
process.stdout.write(str);
if (capture) {
output += str;
} else {
process.stdout.write(str);
}
};

ConsoleWriter.prototype.colorize = function (str, clazz) {
Expand Down Expand Up @@ -115,6 +122,24 @@ function FileWriter(baseDir) {
mkdirp.sync(baseDir);
this.baseDir = baseDir;
}

/**
* static helpers for capturing stdout report output;
* super useful for tests!
*/
FileWriter.startCapture = function () {
capture = true;
};
FileWriter.stopCapture = function () {
capture = false;
};
FileWriter.getOutput = function () {
return output;
};
FileWriter.resetOutput = function () {
output = '';
};

/**
* returns a FileWriter that is rooted at the supplied subdirectory
* @param {String} subdir the subdirectory under which to root the
Expand Down
22 changes: 20 additions & 2 deletions packages/istanbul-reports/lib/text/index.js
Expand Up @@ -112,6 +112,21 @@ function tableHeader(maxNameCols) {
return elements.join(' |') + ' |';
}

function missingLines (node, colorizer) {
var missingLines = node.isSummary() ? [] : node.getFileCoverage().getUncoveredLines();
return colorizer(formatPct(missingLines.join(','), MISSING_COL), 'low');
}

function missingBranches (node, colorizer) {
var branches = node.isSummary() ? {} : node.getFileCoverage().getBranchCoverageByLine(),
missingLines = Object.keys(branches).filter(function (key) {
return branches[key].coverage < 100;
}).map(function (key) {
return key;
});
return colorizer(formatPct(missingLines.join(','), MISSING_COL), 'medium');
}

function tableRow(node, context, colorizer, maxNameCols, level) {
var name = nodeName(node),
metrics = node.getCoverageSummary(),
Expand All @@ -124,15 +139,18 @@ function tableRow(node, context, colorizer, maxNameCols, level) {
colorize = function (str, key) {
return colorizer(str, context.classForPercent(key, mm[key]));
},
missingLines = node.isSummary() ? [] : node.getFileCoverage().getUncoveredLines(),
elements = [];

elements.push(colorize(formatName(name, maxNameCols, level),'statements'));
elements.push(colorize(formatPct(mm.statements),'statements'));
elements.push(colorize(formatPct(mm.branches), 'branches'));
elements.push(colorize(formatPct(mm.functions), 'functions'));
elements.push(colorize(formatPct(mm.lines), 'lines'));
elements.push(colorizer(formatPct(missingLines.join(','), MISSING_COL), 'low'));
if (mm.lines === 100) {
elements.push(missingBranches(node, colorizer));
} else {
elements.push(missingLines(node, colorizer));
}
return elements.join(DELIM) + DELIM;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/istanbul-reports/package.json
Expand Up @@ -17,7 +17,9 @@
},
"devDependencies": {
"chai": "^3.5.0",
"is-windows": "^1.0.1",
"istanbul-lib-coverage": "^1.0.2",
"istanbul-lib-report": "^1.0.0",
"jshint": "^2.8.0",
"mocha": "^3.1.2"
},
Expand Down

0 comments on commit 8a809f8

Please sign in to comment.