Skip to content

Commit

Permalink
feat(reports): add line colorMetric option
Browse files Browse the repository at this point in the history
Makes the report highlight the lines according to the chosen metric.
  • Loading branch information
opichals committed May 13, 2021
1 parent c155900 commit 029594c
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/istanbul-reports/lib/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const summaryTableHeader = [
].join('\n');

function summaryLineTemplate(details) {
const { reportClasses, metrics, file, output } = details;
const { reportClasses, metrics, colorMetric, file, output } = details;
const percentGraph = pct => {
if (!isFinite(pct)) {
return '';
Expand Down Expand Up @@ -193,7 +193,7 @@ function summaryLineTemplate(details) {
.concat(
'<tr>',
`<td class="file ${
reportClasses.statements
reportClasses[colorMetric ? colorMetric : 'statements']
}" data-value="${html.escape(file)}"><a href="${html.escape(
output
)}">${html.escape(file)}</a></td>`,
Expand Down Expand Up @@ -259,6 +259,7 @@ class HtmlReport extends ReportBase {
this.subdir = opts.subdir || '';
this.date = Date();
this.skipEmpty = opts.skipEmpty;
this.colorMetric = opts.colorMetric;
}

getBreadcrumbHtml(node) {
Expand Down Expand Up @@ -354,6 +355,7 @@ class HtmlReport extends ReportBase {
const templateData = this.getTemplateData();
const children = node.getChildren();
const skipEmpty = this.skipEmpty;
const colorMetric = this.colorMetric;

this.fillTemplate(node, templateData, context);
const cw = this.getWriter(context).writeFile(linkMapper.getPath(node));
Expand Down Expand Up @@ -388,6 +390,7 @@ class HtmlReport extends ReportBase {
const data = {
metrics: isEmpty ? fixPct(metrics) : metrics,
reportClasses,
colorMetric,
file: child.getRelativeName(),
output: linkMapper.relativePath(node, child)
};
Expand Down
10 changes: 9 additions & 1 deletion packages/istanbul-reports/lib/text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function tableRow(
level,
skipEmpty,
skipFull,
colorMetric,
missingWidth
) {
const name = nodeName(node);
Expand Down Expand Up @@ -208,7 +209,12 @@ function tableRow(
};
const elements = [];

elements.push(colorize(formatName(name, maxNameCols, level), 'statements'));
elements.push(
colorize(
formatName(name, maxNameCols, level),
colorMetric ? colorMetric : 'statements'
)
);
elements.push(colorize(formatPct(mm.statements), 'statements'));
elements.push(colorize(formatPct(mm.branches, PCT_COLS + 1), 'branches'));
elements.push(colorize(formatPct(mm.functions), 'functions'));
Expand All @@ -235,6 +241,7 @@ class TextReport extends ReportBase {
this.cw = null;
this.skipEmpty = opts.skipEmpty;
this.skipFull = opts.skipFull;
this.colorMetric = opts.colorMetric;
}

onStart(root, context) {
Expand Down Expand Up @@ -278,6 +285,7 @@ class TextReport extends ReportBase {
nodeDepth,
this.skipEmpty,
this.skipFull,
this.colorMetric,
this.missingWidth
);
if (row) {
Expand Down

0 comments on commit 029594c

Please sign in to comment.