From 9a4a31bb1da069085f25fac440aae81a43354fa2 Mon Sep 17 00:00:00 2001 From: Harshil Patel <26harshilpatel11@gmail.com> Date: Fri, 22 Nov 2024 10:04:54 -0500 Subject: [PATCH] test_runner: extend reporterColorMap for diagnostic levels Enhanced to include colors for the following diagnostic levels: : blue : gray : yellow : red Ensures consistency in color-coding across the reporter. Refs: https://github.com/nodejs/node/issues/55922 --- lib/internal/test_runner/reporter/utils.js | 42 +++++++++++++++++----- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/internal/test_runner/reporter/utils.js b/lib/internal/test_runner/reporter/utils.js index 9b6cc96a185a9a..35631789b0b5af 100644 --- a/lib/internal/test_runner/reporter/utils.js +++ b/lib/internal/test_runner/reporter/utils.js @@ -17,7 +17,7 @@ const inspectOptions = { }; const reporterUnicodeSymbolMap = { - '__proto__': null, + __proto__: null, 'test:fail': '\u2716 ', 'test:pass': '\u2714 ', 'test:diagnostic': '\u2139 ', @@ -27,7 +27,7 @@ const reporterUnicodeSymbolMap = { }; const reporterColorMap = { - '__proto__': null, + __proto__: null, get 'test:fail'() { return colors.red; }, @@ -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) { @@ -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) { @@ -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'];