Skip to content

Commit

Permalink
test_runner: extend reporterColorMap for diagnostic levels
Browse files Browse the repository at this point in the history
Enhanced  to include colors for the following
diagnostic levels:
 : blue
 : gray
 : yellow
 : red

Ensures consistency in color-coding across the reporter.

Refs: nodejs#55922
  • Loading branch information
hpatel292-seneca committed Nov 22, 2024
1 parent dfbace2 commit 9a4a31b
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions lib/internal/test_runner/reporter/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const inspectOptions = {
};

const reporterUnicodeSymbolMap = {
'__proto__': null,
__proto__: null,
'test:fail': '\u2716 ',
'test:pass': '\u2714 ',
'test:diagnostic': '\u2139 ',
Expand All @@ -27,7 +27,7 @@ const reporterUnicodeSymbolMap = {
};

const reporterColorMap = {
'__proto__': null,
__proto__: null,
get 'test:fail'() {
return colors.red;
},
Expand All @@ -37,6 +37,18 @@ const reporterColorMap = {
get 'test:diagnostic'() {
return colors.blue;
},
get info() {
return colors.blue;
},
get debug() {
return colors.gray;
},
get warn() {
return colors.yellow;
},
get error() {
return colors.red;
},
};

function indent(nesting) {
Expand All @@ -54,16 +66,26 @@ function formatError(error, indent) {
const message = ArrayPrototypeJoin(
RegExpPrototypeSymbolSplit(
hardenRegExp(/\r?\n/),
inspectWithNoCustomRetry(err, inspectOptions),
), `\n${indent} `);
inspectWithNoCustomRetry(err, inspectOptions)
),
`\n${indent} `
);
return `\n${indent} ${message}\n`;
}

function formatTestReport(type, data, prefix = '', indent = '', hasChildren = false) {
function formatTestReport(
type,
data,
prefix = '',
indent = '',
hasChildren = false
) {
let color = reporterColorMap[type] ?? colors.white;
let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
const { skip, todo } = data;
const duration_ms = data.details?.duration_ms ? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}` : '';
const duration_ms = data.details?.duration_ms
? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}`
: '';
let title = `${data.name}${duration_ms}`;

if (skip !== undefined) {
Expand All @@ -72,9 +94,11 @@ function formatTestReport(type, data, prefix = '', indent = '', hasChildren = fa
title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
}
const error = formatError(data.details?.error, indent);
const err = hasChildren ?
(!error || data.details?.error?.failureType === 'subtestsFailed' ? '' : `\n${error}`) :
error;
const err = hasChildren
? !error || data.details?.error?.failureType === 'subtestsFailed'
? ''
: `\n${error}`
: error;
if (skip !== undefined) {
color = colors.gray;
symbol = reporterUnicodeSymbolMap['hyphen:minus'];
Expand Down

0 comments on commit 9a4a31b

Please sign in to comment.