-
-
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
Human-readable colors for jest-matchers snapshots #3119
Conversation
cc: @DmitriiAbramov |
packages/jest-matchers/package.json
Outdated
@@ -12,5 +12,10 @@ | |||
"jest-matcher-utils": "^19.0.0", | |||
"jest-message-util": "^19.0.0", | |||
"jest-regex-util": "^19.0.0" | |||
}, | |||
"devDependencies": { | |||
"ansi-regex": "^2.1.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.
Why are ansi-regex
and ansi-styles
added?
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.
Because I use them in here: https://github.com/facebook/jest/pull/3119/files#diff-5d7e608b44e8080e7491366117a2025fR20
They're also already available through chalk
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.
Can you make ansi-styles and ansi-regex devDependencies of the top level package.json instead? jest-snapshot should stay here but please use the latest version (19.0.2).
Codecov Report
@@ Coverage Diff @@
## master #3119 +/- ##
=========================================
- Coverage 69.4% 69.2% -0.21%
=========================================
Files 156 157 +1
Lines 5514 5530 +16
Branches 3 3
=========================================
Hits 3827 3827
- Misses 1686 1702 +16
Partials 1 1
Continue to review full report at Codecov.
|
Lovely! This makes snapshot files a lot more readable. Can we make this a utility function somewhere and use it for all the matcher snapshots? I think we also do this in other files. |
@kentaromiura advised that it may be a good idea to write a custom |
packages/jest-snapshot/src/index.js
Outdated
|
||
return toMatchSnapshot.call(this, error.message); | ||
return toMatchSnapshot.call(this, errorMessage); |
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.
We pass a string to toMatchSnapshot
so we either need to:
- add a symbol, so we can test for it in the snapshot serializer
- change nothing and test for ansi characters inside the plugin (which will alter our regular snapshots too)
- pass whole Error object and test for JestAssertionError in
toMatchSnapshot
and extract its message if necessary
I like the idea overall but tagging Jest code with |
Wow. That's sweet |
i wonder if it would make sense to go the other direction. |
🎉 |
Generated by 🚫 dangerJS |
* Human-readable colors for jest-matchers snapshots * Use ConvertAnsi pretty-format plugin as snapshotSerializer * Convert ansi escapes in all snapshots
* Human-readable colors for jest-matchers snapshots * Use ConvertAnsi pretty-format plugin as snapshotSerializer * Convert ansi escapes in all snapshots
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
Storing ANSI characters in snapshots of
jest-matchers
isn't very helpful and adds unnecessary noise, making it harder to review. This is a proposal to change it to something more human-readable like<green>
or<red>
or</>
for color reset sequence.Test plan
Look at snapshots diff