-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
test_runner: add level-based diagnostic handling for reporter #55964
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
Hi @pmarchini, Please review and let me know if you want me to change anything. |
Hey @hpatel292-seneca, I won't be able to review until Monday. I've also requested other reviews in the meantime. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #55964 +/- ##
==========================================
- Coverage 87.99% 87.96% -0.04%
==========================================
Files 653 656 +3
Lines 188091 188396 +305
Branches 35941 35975 +34
==========================================
+ Hits 165516 165725 +209
- Misses 15751 15832 +81
- Partials 6824 6839 +15
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes since this already has an approval. This also needs docs and tests.
get 'debug'() { | ||
return colors.gray; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the debug level. The reporter stream is not a generic logger, and we have other ways (NODE_DEBUG
) of adding debug output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove that. And I have a question so this CI https://github.com/nodejs/node/actions/runs/11983534043/job/33427085217?pr=55964 failed and it's for First commit message adheres to guidelines / lint-commit-message (pull_request)
so should I change commit history??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_runner: add level to diagnostics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I am asking if I should change the commit history and force push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Yes, please. You'll need to avoid merge commits too, as the tooling does not handle them well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmarchini Ok so I am taking reference from this tests
https://github.com/nodejs/node/blob/main/test/fixtures/test-runner/output/coverage-width-80-color.mjs
https://github.com/nodejs/node/blob/main/test/fixtures/test-runner/output/coverage-width-80-color.snapshot
and based on that I wrote this test.
fixtures/test-runner/output/spec_reporter_diagnostic_levels.mjs
// Flags: --test-reporter=spec
import { test } from 'node:test';
import { TestsStream } from '../../../lib/internal/test_runner/tests_stream.js';
process.env.FORCE_COLOR = '3';
const testsStream = new TestsStream();
test('Diagnostic Levels Color Output', () => {
testsStream.diagnostic(1, {}, 'Info-level message', 'info');
testsStream.diagnostic(1, {}, 'Warning-level message', 'warn');
testsStream.diagnostic(1, {}, 'Error-level message', 'error');
});
and add this in test-runner-output.mjs
{
name: 'test-runner/output/spec_reporter_diagnostic_levels.mjs',
transform: specTransform,
tty: true,
}
now I am running tools/test.py test/parallel/test-runner-output.mjs --snapshot
but it's not creating snap for added test.
How I can create snaps??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot you were working in a Windows environment. Considering this, I would suggest picking a different approach. You could add a test to node/test/parallel/test-runner-coverage-thresholds.js
that forces the colors via the environment variable in the spawn
, and check that the error message 'coverage does not meet...' is displayed in red.
Note: you need to set the reporter to spec
.
This is also because test-runner-output.mjs
is intended for 'e2e' testing of the test runner's output under specific circumstances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmarchini @cjihrig Thank you so much for your help. It wouldn't be possible without your help.
I ran test cases and here is output
I printed raw output in test case and here is output
and here is test case:
test(`test failing ${coverage.flag} with red color`, () => {
const result = spawnSync(process.execPath, [
'--test',
'--experimental-test-coverage',
`${coverage.flag}=99`,
'--test-reporter', 'spec',
fixture,
], {
env: { ...process.env, FORCE_COLOR: '3' },
});
const stdout = result.stdout.toString();
const redColorRegex = /\u001b\[31mℹ Error: \d{2}\.\d{2}% \w+ coverage does not meet threshold of 99%/;
assert.match(stdout, redColorRegex, 'Expected red color code not found in diagnostic message');
assert.strictEqual(result.status, 1);
assert(!findCoverageFileForPid(result.pid));
});
If it looks good to you I can commit it and you can review the whole PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pmarchini @cjihrig ,
Could we please land this PR if no change is required?
Added a parameter 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 - info : yellow - warn : red - error 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
implemented requested change by removing debug from reporterColorMap Refs: nodejs#55964 (review)
188f357
to
038b0f8
Compare
updated the documentation for the 'test:diagnostic' event to include the new level parameter. clarified its purpose, default value, and possible severity levels ('info', 'warn', 'error'). Fixes: nodejs#55922
Add a test in to verify that the diagnostic error messages about unmet coverage thresholds are displayed in red when using the spec reporter. Fixes: nodejs#55922
Hi @pmarchini @cjihrig, |
Hi, @pmarchini @cjihrig I will add one more commit for fixing the lint error.
Should I go ahead and send commit? |
Sure 🚀 |
Added eslint-disable comment to bypass no-control-regex. This allows testing ANSI escape sequences for red color in error messages without triggering lint errors. Fixes: nodejs#55922
@pmarchini I did. Thanks |
Hi @pmarchini @cjihrig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except the documentation: LGTM
doc/api/test.md
Outdated
* `level` {string} The severity level of the diagnostic message, which determines its output color in the reporter. | ||
Possible values are: | ||
* `'info'`: Informational messages. | ||
* `'warn'`: Warnings. | ||
* `'error'`: Errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `level` {string} The severity level of the diagnostic message, which determines its output color in the reporter. | |
Possible values are: | |
* `'info'`: Informational messages. | |
* `'warn'`: Warnings. | |
* `'error'`: Errors. | |
* `level` {string} The severity level of the diagnostic message. | |
Possible values are: | |
* `'info'`: Informational messages. | |
* `'warn'`: Warnings. | |
* `'error'`: Errors. |
I'm adding this suggestion since the color is a "side-effect" and happens only in the spec
reporter.
This information could help users while creating a new custom reporter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update and commit it. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pmarchini, Docs is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmarchini Please let me know if more changes is required.
Updated the description of the parameter to note that color output is specific to the spec reporter. This helps users understand its behavior and create custom reporters with accurate expectations. Fixes: nodejs#55922
This fixes #55922
Change summary
Updated the reporter.diagnostic to accept level parameter like this
Then I updated
#handleEvent
like thisAnd I am Updated
reporterColorMap
like thisand color already contain logic for this colors
I also set the reporter.diagnostic call from test.js like this (level="Error")
Here is Demo output: