Skip to content
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

Merged
merged 4 commits into from
Feb 19, 2018

Conversation

ranyitz
Copy link
Contributor

@ranyitz ranyitz commented Feb 15, 2018

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.

@@ -15,6 +15,7 @@ import type {
LogTimers,
} from 'types/Console';

import assert from 'assert';
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node:

image

Chrome:
image

The output is pretty different

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer thoughts?

@codecov-io
Copy link

codecov-io commented Feb 15, 2018

Codecov Report

Merging #5576 into master will increase coverage by 0.18%.
The diff coverage is 25%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/jest-util/src/Console.js 56.86% <25%> (+12.86%) ⬆️
packages/jest-util/src/buffered_console.js 61.11% <25%> (+13.94%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bea889c...b51559d. Read the comment docs.

try {
assert(!!args[0], ...args.slice(1));
} catch (error) {
this._log('assert', error.toString());
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

if (args[0]) {
this._log('assert', format(...args.slice(1)));
try {
assert(!!args[0], ...args.slice(1));
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, fixed

@ranyitz
Copy link
Contributor Author

ranyitz commented Feb 19, 2018

@thymikee Is there anything left to do?

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants