Skip to content

test_runner: add level-based diagnostic handling for reporter - #55957

Closed
hpatel292-seneca wants to merge 4 commits into
nodejs:mainfrom
hpatel292-seneca:issue-55922
Closed

test_runner: add level-based diagnostic handling for reporter#55957
hpatel292-seneca wants to merge 4 commits into
nodejs:mainfrom
hpatel292-seneca:issue-55922

Conversation

@hpatel292-seneca

Copy link
Copy Markdown

This fixes#55922

Change summary

Updated the reporter.diagnostic to accept level parameter like this

diagnostic(nesting,loc,message,level='info'){this[kEmitMessage]('test:diagnostic',{__proto__: null,
nesting,
message,
level,
...loc,});}

Then I updated #handleEvent like this

 #handleEvent({ type, data }){switch(type){case'test:fail':
if(data.details?.error?.failureType!==kSubtestsFailed){ArrayPrototypePush(this.#failedTests,data);}returnthis.#handleTestReportEvent(type,data);case'test:pass':
returnthis.#handleTestReportEvent(type,data);case'test:start':
ArrayPrototypeUnshift(this.#stack,{__proto__: null, data, type });break;case'test:stderr':
case'test:stdout':
returndata.message;case'test:diagnostic': // Here I added logicconstdiagnosticColor=reporterColorMap[data.level]||reporterColorMap['test:diagnostic'];return`${diagnosticColor}${indent(data.nesting)}${reporterUnicodeSymbolMap[type]}${data.message}${colors.white}\n`;case'test:coverage':
returngetCoverageReport(indent(data.nesting),data.summary,reporterUnicodeSymbolMap['test:coverage'],colors.blue,true);}}

And I am Updated reporterColorMap like this

constreporterColorMap={__proto__: null,get'test:fail'(){returncolors.red;},get'test:pass'(){returncolors.green;},get'test:diagnostic'(){returncolors.blue;},getinfo(){returncolors.blue;},getdebug(){returncolors.gray;},getwarn(){returncolors.yellow;},geterror(){returncolors.red;},};

and color already contain logic for this colors

I also set the reporter.diagnostic call from test.js like this (level="Error")

if(actual<threshold){harness.success=false;process.exitCode=kGenericUserError;reporter.diagnostic(nesting,loc,`Error: ${NumberPrototypeToFixed(actual,2)}% ${name} coverage does not meet threshold of ${threshold}%.`,'error'// Level is set to error for red color);}

Here is Demo output:
image

Added a parameter to to allow
severity-based formatting for diagnostic messages. Defaults to 'info'.
This update enables better control over message presentation
(e.g., coloring) based on severity levels such as 'info', 'warn',
and 'error'.
Refs: nodejs#55922
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
Enhanced to include colors for the following
diagnostic levels:
: blue
: gray
: yellow
: red
Ensures consistency in color-coding across the reporter.
Refs: nodejs#55922
Updated coverage threshold checks in to use the
parameter when calling . Errors now use the
'error' level for red-colored formatting.
This ensures coverage errors are highlighted effectively in the output.
Fixes: nodejs#55922
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Nov 22, 2024
@hpatel292-seneca

Copy link
Copy Markdown
Author

Hi @pmarchini, Here is the PR and the demo of it I tested locally. I am not sure where to add test case for the change, I read this https://github.com/nodejs/node/blob/main/doc/contributing/writing-tests.md but I am still not sure and I tried searching existing test case for

to look for reference but I cant find it.

@hpatel292-seneca

Copy link
Copy Markdown
Author

And I just noticed that my vscode formatter formatted the files I worked with. Do you want that or you want me to revert it back?

@pmarchini

Copy link
Copy Markdown
Member

And I just noticed that my vscode formatter formatted the files I worked with. Do you want that or you want me to revert it back?

Hey @hpatel292-seneca, about formatting absolutely, only changes strictly related to the issue must be present in the PR, also make sure you run linting via make commands.

Also, have you run the tests? I would expect these changes to potentially break some existing tests

@hpatel292-seneca

Copy link
Copy Markdown
Author

Hi @pmarchini, Run tests and I got few tests failing which I tried to look at but not able to understand exact error, but I tried building Node based on main branch without my changes and tried running test cases and it is also failing same test cases.

Here is screenshot of tests failing on main
image

And here is tests failing on my issue branch
image

All the tests which are failing are same. Maybe my pc is missing some configuration!

@pmarchini

Copy link
Copy Markdown
Member

I'm closing this PR as it duplicates:
#55964

Please avoid opening duplicate PRs 😊

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ciPRs that need a full CI run.test_runnerIssues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a level parameter to test runner diagnostics

3 participants

@hpatel292-seneca@nodejs-github-bot@pmarchini