-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix console & buffered console assert behaviour #5576
Conversation
@@ -15,6 +15,7 @@ import type { | |||
LogTimers, | |||
} from 'types/Console'; | |||
|
|||
import assert from 'assert'; |
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.
This is correct in node env, not in jsdom. Unsure if we care about that differentiation?
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.
The differences are small, but I'm not sure it should affect this fix
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.
@SimenB If I understand correctly, jsdom forwards its output to the Node.js console by default.
I'm not sure that we should print different messages (AssertionError [ERR_ASSERTION]
/Assertion failed
) depends on the environment.
What do you suggest?
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.
@cpojer thoughts?
Codecov Report
@@ Coverage Diff @@
## master #5576 +/- ##
==========================================
+ Coverage 60.65% 60.83% +0.18%
==========================================
Files 214 214
Lines 7314 7316 +2
Branches 4 3 -1
==========================================
+ Hits 4436 4451 +15
+ Misses 2877 2864 -13
Partials 1 1
Continue to review full report at Codecov.
|
8fa6f29
to
d27417c
Compare
packages/jest-util/src/Console.js
Outdated
try { | ||
assert(!!args[0], ...args.slice(1)); | ||
} catch (error) { | ||
this._log('assert', error.toString()); |
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.
https://nodejs.org/api/console.html#console_console_assert_value_message_args
Note: The console.assert() method is implemented differently in Node.js than the console.assert() method available in browsers.
Specifically, in browsers, calling console.assert() with a falsy assertion will cause the message to be printed to the console without interrupting execution of subsequent code. In Node.js, however, a falsy assertion will cause an AssertionError to be thrown.
Should we respect that? We'd have to pass environment, or detect jsdom/node otherwise. Personally I'd like console.assert
errors to always be caught, like in browsers.
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.
Yes, I agree with you about it, because otherwise, the assertion error would fail the test.
packages/jest-util/src/Console.js
Outdated
if (args[0]) { | ||
this._log('assert', format(...args.slice(1))); | ||
try { | ||
assert(!!args[0], ...args.slice(1)); |
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 just use assert(...args)
since extra arguments are irrelevant to it. Same for buffered console.
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 agree, fixed
2769e7a
to
db08ab1
Compare
db08ab1
to
b51559d
Compare
@thymikee Is there anything left to do? |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This is a fix for #5574
There was a mistake in #5514, where the
console.assert
behaviour was accidenitly implemented wrong.Here there is a fix for the tests and the behaviour to use
assert
module and log when there is an assertion error.