-
-
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
Jest diff numbers and booleans #7605
Conversation
Thanks again @jeysal! @pedrottimark how does this fit into #6961 and #7557? |
Yeah I saw those two open PRs too - might have small merge conflicts but it's semantically different concerns so I think we should be fine. |
Definite yes to the change from The exceptions of @jeysal can you summarize the pros and cons of adding a new option to keep the current behavior (therefore a breaking change) versus to give the improvement (therefore opt-in and not a breaking change). According to npm there are 88 dependents. EDIT: To clarify a possible misunderstanding, I don’t mean that users of CLI tool shouldn’t need to specify an option to get desired behavior. |
Con - the breaking change 😄
|
On the too close coupling: |
I think in the long run we want |
Yeah that would be cool - then we could remove the special handling altogether. Do you think that as it is the number/boolean special handling should be in jest-diff behind |
035b03c
to
23dc84f
Compare
I think I'm leaning towards the no- With inline highlights we could have the output from the matcher like this:
since it would know we only have 2 single-line values to compare which would be so awesome. Anyway, @pedrottimark has it probably all figured out couple of months ahead, so he's the best person to answer |
Yeah I think that would be better as well. If we go this route, probably best to do it now though, otherwise we have a breaking change again when we remove |
Codecov Report
@@ Coverage Diff @@
## master #7605 +/- ##
==========================================
+ Coverage 68.26% 68.27% +0.01%
==========================================
Files 249 249
Lines 9623 9627 +4
Branches 6 6
==========================================
+ Hits 6569 6573 +4
Misses 3052 3052
Partials 2 2
Continue to review full report at Codecov.
|
+1 to not add a |
Okay, I'll try to build the required |
We can regress a tiny bit on the output from (preferable would be for both to land at the same time, of course) |
Thank you for patience while this simmered in my mental slow cooker. I will share some thoughts this afternoon. For long view, see #7603 (comment) |
23dc84f
to
367343a
Compare
I've removed all things |
Oh right, node assert... |
Node assert code should probably live in |
Given that shouldPrintDiff(a, b) ? jestDiff(a, b, options) : null , maybe extracting it into |
I'm fine with that as a dep, seems natural that a matcher utility can also do diffing |
bb9a782
to
6f7d209
Compare
Done. This also removed two |
Also using the |
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 great, thank you!
@jeysal Brilliant solution to make the change available to other dependents! Look forward to collaborating on future improvements to reports in Jest, if you are interested :) |
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
Currently,
jest-diff
returnsnull
when diffing numbers or booleans (orNO_DIFF_MESSAGE
if they are equal).This is because the matchers that use jest-diff already print something like
if they differ, so the jest-diff output would be redundant.
This behavior is unintuitive if you are using
jest-diff
for something other than Jest's test failure output.I stumbled upon this trying to build a
diff
-like CLI forjest-diff
.It was also quite inexplicable to me when I first read the jest-diff code ("why does it just not do anything if a and b are numbers?"), so I think this piece of code needed clarification in general.
This PR changes jest-diff to behave like normal diffing by default, with an
omitTrivial
option that the matchers use to tell jest-diff not to generate a diff between numbers or booleans.Test plan
Added tests for numbers and booleans to
diff.test
.e2e tests unchanged, confirming that this does not change the overall behavior of Jest.
One exception: Along the way, I also fixed the following contradictory output :D