Updating NPM dependencies

This commit is contained in:
Drew Heavner
2020-11-11 13:30:52 +00:00
committed by GitHub
parent 7a6fb66c63
commit bd487ef324
9068 changed files with 1400893 additions and 587661 deletions

View File

@@ -1,14 +1,16 @@
/*
Copyright 2012-2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
Copyrights licensed under the New BSD License. See the accompanying LICENSE
file for terms.
*/
'use strict';
const { ReportBase } = require('istanbul-lib-report');
const PCT_COLS = 9;
const MISSING_COL = 18;
const NAME_COL = 4;
const PCT_COLS = 7;
const MISSING_COL = 17;
const TAB_SIZE = 1;
const DELIM = ' |';
const COL_DELIM = '-|';
const DELIM = ' | ';
function padding(num, ch) {
let str = '';
@@ -28,17 +30,21 @@ function fill(str, width, right, tabs) {
const remaining = width - leadingSpaces;
const leader = padding(leadingSpaces);
let fmtStr = '';
let fillStr;
const strlen = str.length;
if (remaining > 0) {
const strlen = str.length;
let fillStr;
if (remaining >= strlen) {
fillStr = padding(remaining - strlen);
fmtStr = right ? fillStr + str : str + fillStr;
} else {
fmtStr = str.substring(strlen - remaining);
fmtStr = '... ' + fmtStr.substring(4);
fillStr = '...';
const length = remaining - fillStr.length;
str = str.substring(strlen - length);
right = true;
}
fmtStr = right ? fillStr + str : str + fillStr;
}
return leader + fmtStr;
@@ -52,6 +58,53 @@ function formatPct(pct, width) {
return fill(pct, width || PCT_COLS, true, 0);
}
function nodeMissing(node) {
if (node.isSummary()) {
return '';
}
const metrics = node.getCoverageSummary();
const isEmpty = metrics.isEmpty();
const lines = isEmpty ? 0 : metrics.lines.pct;
let coveredLines;
const fileCoverage = node.getFileCoverage();
if (lines === 100) {
const branches = fileCoverage.getBranchCoverageByLine();
coveredLines = Object.entries(branches).map(([key, { coverage }]) => [
key,
coverage === 100
]);
} else {
coveredLines = Object.entries(fileCoverage.getLineCoverage());
}
let newRange = true;
const ranges = coveredLines
.reduce((acum, [line, hit]) => {
if (hit) newRange = true;
else {
line = parseInt(line);
if (newRange) {
acum.push([line]);
newRange = false;
} else acum[acum.length - 1][1] = line;
}
return acum;
}, [])
.map(range => {
const { length } = range;
if (length === 1) return range[0];
return `${range[0]}-${range[1]}`;
});
return [].concat(...ranges).join(',');
}
function nodeName(node) {
return node.getRelativeName() || 'All files';
}
@@ -66,67 +119,49 @@ function depthFor(node) {
return ret;
}
function findNameWidth(node, context) {
function nullDepthFor() {
return 0;
}
function findWidth(node, context, nodeExtractor, depthFor = nullDepthFor) {
let last = 0;
const compareWidth = function(node) {
const depth = depthFor(node);
const idealWidth = TAB_SIZE * depth + nodeName(node).length;
if (idealWidth > last) {
last = idealWidth;
}
};
function compareWidth(node) {
last = Math.max(
last,
TAB_SIZE * depthFor(node) + nodeExtractor(node).length
);
}
const visitor = {
onSummary(node) {
compareWidth(node);
},
onDetail(node) {
compareWidth(node);
}
onSummary: compareWidth,
onDetail: compareWidth
};
node.visit(context.getVisitor(visitor));
return last;
}
function makeLine(nameWidth) {
function makeLine(nameWidth, missingWidth) {
const name = padding(nameWidth, '-');
const pct = padding(PCT_COLS, '-');
const elements = [];
elements.push(name);
elements.push(pct);
elements.push(padding(PCT_COLS + 1, '-'));
elements.push(pct);
elements.push(pct);
elements.push(pct);
elements.push(padding(MISSING_COL, '-'));
return elements.join(COL_DELIM) + COL_DELIM;
elements.push(padding(missingWidth, '-'));
return elements.join(DELIM.replace(/ /g, '-')) + '-';
}
function tableHeader(maxNameCols) {
function tableHeader(maxNameCols, missingWidth) {
const elements = [];
elements.push(formatName('File', maxNameCols, 0));
elements.push(formatPct('% Stmts'));
elements.push(formatPct('% Branch'));
elements.push(formatPct('% Branch', PCT_COLS + 1));
elements.push(formatPct('% Funcs'));
elements.push(formatPct('% Lines'));
elements.push(formatPct('Uncovered Line #s', MISSING_COL));
return elements.join(' |') + ' |';
}
function missingLines(node, colorizer) {
const missingLines = node.isSummary()
? []
: node.getFileCoverage().getUncoveredLines();
return colorizer(formatPct(missingLines.join(','), MISSING_COL), 'low');
}
function missingBranches(node, colorizer) {
const branches = node.isSummary()
? {}
: node.getFileCoverage().getBranchCoverageByLine();
const missingLines = Object.keys(branches)
.filter(key => branches[key].coverage < 100)
.map(key => key);
return colorizer(formatPct(missingLines.join(','), MISSING_COL), 'medium');
elements.push(formatName('Uncovered Line #s', missingWidth));
return elements.join(DELIM) + ' ';
}
function isFull(metrics) {
@@ -145,7 +180,8 @@ function tableRow(
maxNameCols,
level,
skipEmpty,
skipFull
skipFull,
missingWidth
) {
const name = nodeName(node);
const metrics = node.getCoverageSummary();
@@ -174,66 +210,89 @@ function tableRow(
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.branches, PCT_COLS + 1), 'branches'));
elements.push(colorize(formatPct(mm.functions), 'functions'));
elements.push(colorize(formatPct(mm.lines), 'lines'));
if (mm.lines === 100) {
elements.push(missingBranches(node, colorizer));
} else {
elements.push(missingLines(node, colorizer));
elements.push(
colorizer(
formatName(nodeMissing(node), missingWidth),
mm.lines === 100 ? 'medium' : 'low'
)
);
return elements.join(DELIM) + ' ';
}
class TextReport extends ReportBase {
constructor(opts) {
super();
opts = opts || {};
const { maxCols } = opts;
this.file = opts.file || null;
this.maxCols = maxCols != null ? maxCols : process.stdout.columns || 80;
this.cw = null;
this.skipEmpty = opts.skipEmpty;
this.skipFull = opts.skipFull;
}
return elements.join(DELIM) + DELIM;
}
function TextReport(opts) {
opts = opts || {};
this.file = opts.file || null;
this.maxCols = opts.maxCols || 0;
this.cw = null;
this.skipEmpty = opts.skipEmpty;
this.skipFull = opts.skipFull;
}
onStart(root, context) {
this.cw = context.writer.writeFile(this.file);
this.nameWidth = Math.max(
NAME_COL,
findWidth(root, context, nodeName, depthFor)
);
this.missingWidth = Math.max(
MISSING_COL,
findWidth(root, context, nodeMissing)
);
TextReport.prototype.onStart = function(root, context) {
const statsWidth = 4 * (PCT_COLS + 2) + MISSING_COL;
if (this.maxCols > 0) {
const pct_cols = DELIM.length + 4 * (PCT_COLS + DELIM.length) + 2;
this.cw = context.writer.writeFile(this.file);
this.nameWidth = findNameWidth(root, context);
if (this.maxCols > 0) {
const maxRemaining = this.maxCols - statsWidth - 2;
if (this.nameWidth > maxRemaining) {
this.nameWidth = maxRemaining;
const maxRemaining = this.maxCols - (pct_cols + MISSING_COL);
if (this.nameWidth > maxRemaining) {
this.nameWidth = maxRemaining;
this.missingWidth = MISSING_COL;
} else if (this.nameWidth < maxRemaining) {
const maxRemaining = this.maxCols - (this.nameWidth + pct_cols);
if (this.missingWidth > maxRemaining) {
this.missingWidth = maxRemaining;
}
}
}
const line = makeLine(this.nameWidth, this.missingWidth);
this.cw.println(line);
this.cw.println(tableHeader(this.nameWidth, this.missingWidth));
this.cw.println(line);
}
onSummary(node, context) {
const nodeDepth = depthFor(node);
const row = tableRow(
node,
context,
this.cw.colorize.bind(this.cw),
this.nameWidth,
nodeDepth,
this.skipEmpty,
this.skipFull,
this.missingWidth
);
if (row) {
this.cw.println(row);
}
}
const line = makeLine(this.nameWidth);
this.cw.println(line);
this.cw.println(tableHeader(this.nameWidth));
this.cw.println(line);
};
TextReport.prototype.onSummary = function(node, context) {
const nodeDepth = depthFor(node);
const row = tableRow(
node,
context,
this.cw.colorize.bind(this.cw),
this.nameWidth,
nodeDepth,
this.skipEmpty,
this.skipFull
);
if (row) {
this.cw.println(row);
onDetail(node, context) {
return this.onSummary(node, context);
}
};
TextReport.prototype.onDetail = function(node, context) {
return this.onSummary(node, context);
};
TextReport.prototype.onEnd = function() {
this.cw.println(makeLine(this.nameWidth));
this.cw.close();
};
onEnd() {
this.cw.println(makeLine(this.nameWidth, this.missingWidth));
this.cw.close();
}
}
module.exports = TextReport;