Skip to content

Commit

Permalink
test_runner: enhance #handleEvent to handle diagnostic levels
Browse files Browse the repository at this point in the history
Updated  to process the  parameter for
 events. Messages are now formatted with
colors based on the  (e.g., 'info', 'warn',
'error').

This change ensures diagnostic messages are visually distinct,
improving clarity and reducing debugging effort during test runs.

Refs: nodejs#55922
  • Loading branch information
hpatel292-seneca committed Nov 22, 2024
1 parent 5291c1d commit dfbace2
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions lib/internal/test_runner/reporter/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,27 @@ class SpecReporter extends Transform {
assert(parent.type === 'test:start');
const msg = parent.data;
ArrayPrototypeUnshift(this.#reported, msg);
prefix += `${indent(msg.nesting)}${reporterUnicodeSymbolMap['arrow:right']}${msg.name}\n`;
prefix += `${indent(msg.nesting)}${
reporterUnicodeSymbolMap['arrow:right']
}${msg.name}\n`;
}
let hasChildren = false;
if (this.#reported[0] && this.#reported[0].nesting === data.nesting && this.#reported[0].name === data.name) {
if (
this.#reported[0] &&
this.#reported[0].nesting === data.nesting &&
this.#reported[0].name === data.name
) {
ArrayPrototypeShift(this.#reported);
hasChildren = true;
}
const indentation = indent(data.nesting);
return `${formatTestReport(type, data, prefix, indentation, hasChildren)}\n`;
return `${formatTestReport(
type,
data,
prefix,
indentation,
hasChildren
)}\n`;
}
#handleEvent({ type, data }) {
switch (type) {
Expand All @@ -70,10 +82,19 @@ class SpecReporter extends Transform {
case 'test:stdout':
return data.message;
case 'test:diagnostic':
return `${reporterColorMap[type]}${indent(data.nesting)}${reporterUnicodeSymbolMap[type]}${data.message}${colors.white}\n`;
const diagnosticColor =
reporterColorMap[data.level] || reporterColorMap['test:diagnostic'];
return `${diagnosticColor}${indent(data.nesting)}${
reporterUnicodeSymbolMap[type]
}${data.message}${colors.white}\n`;
case 'test:coverage':
return getCoverageReport(indent(data.nesting), data.summary,
reporterUnicodeSymbolMap['test:coverage'], colors.blue, true);
return getCoverageReport(
indent(data.nesting),
data.summary,
reporterUnicodeSymbolMap['test:coverage'],
colors.blue,
true
);
}
}
_transform({ type, data }, encoding, callback) {
Expand All @@ -84,7 +105,9 @@ class SpecReporter extends Transform {
callback(null, '');
return;
}
const results = [`\n${reporterColorMap['test:fail']}${reporterUnicodeSymbolMap['test:fail']}failing tests:${colors.white}\n`];
const results = [
`\n${reporterColorMap['test:fail']}${reporterUnicodeSymbolMap['test:fail']}failing tests:${colors.white}\n`,
];
for (let i = 0; i < this.#failedTests.length; i++) {
const test = this.#failedTests[i];
const formattedErr = formatTestReport('test:fail', test);
Expand Down

0 comments on commit dfbace2

Please sign in to comment.