Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reports): add line colorMetric option #608

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/istanbul-reports/lib/html/index.js
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
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