-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Improving error messages and codes in jest-console, matcher.js #53743
Improving error messages and codes in jest-console, matcher.js #53743
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @MericKarabulut! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
Thank you for starting this PR. It looks like some tests using |
pls do not merge yet i spotted the problem. The problem accurs when test use |
808734c
to
595079b
Compare
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 fact that code get refactored together with the new changes added makes it a bit harder to review. What's the most important part I should be looking at exactly?
Yeah you are right, thank you for the review. During the code addition phase, I retained the original message and included a reference in the documentation. For the modifications in the displayed message, you can refer to the The most important aspect to note was ensuring that the original functionality of matchers remained intact and performed with the same efficiency. As using Jest's built-in object comparison mechanism within the spyInfo function was not possible. Instead,I had to adopt an alternative approach for comparison replacing |
595079b
to
f931752
Compare
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.
Excellent work on this PR. I have tested it with the custom code added:
console.log( true, null );
console.warn( '123', 'ccc' );
console.error( [ '123' ], { a: 'ccc' } );
It all works as expected:



All the existing unit tests for @wordpress/jest-console
still pass.
I left a super tiny comment, which is only to improve readability. I would appreciate also adding an entry to the CHANGELOG file:
https://github.com/WordPress/gutenberg/blob/trunk/packages/jest-console/CHANGELOG.md
along these lines:
### Enhancement
- Improved error messages and codes printed on the console ([#53743](https://github.com/WordPress/gutenberg/pull/53743)).
By the way, thank you so much for the detailed explanation of the changes applied. In retrospect, I think it would help if the commits would get split into two steps where the refactoring would be an atomic commit. No need to change anything now, but I thought I would share that.
7c2293e
to
955295e
Compare
Changes added 👍, It was a pleasure to contribute. In my future contributions, I'll make sure to separate my commits in a clear manner. Thank you for review and your guidance. 🙏 |
Congratulations on your first merged pull request, @MericKarabulut! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
Warning: Type of PR label error To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. |
What?
This pull request addresses issue #17072, it improves error messages and enhanges code maintainability.
Why?
This fix is importantbecause
jest-console
gives confusing errors when developers use console messages for their testes. These unclear error messages can easily confuse developers and make them think that they've set up their testing tools wrong or that something is broken in their tests.How?
I added "console.log() should not be used unless explicitly expected, see file://gutenberg/packages/jest-console/README.md."(using
methodName
parameter so it works with all console metods) and I contributed by introducing functions likecreateErrorMessage
andcreateSpyInfo
, for setting the stage for possible future improvements to this file.Testing Instructions
example.test.js
filenpm run test:unit ./example.test.js
Testing Instructions for Keyboard
none
Screenshots or screencast
none