-
-
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
Display outer element and trailing newline consistently in jest-diff #4520
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4520 +/- ##
==========================================
- Coverage 56.83% 56.82% -0.02%
==========================================
Files 186 186
Lines 6306 6304 -2
Branches 3 3
==========================================
- Hits 3584 3582 -2
Misses 2721 2721
Partials 1 1
Continue to review full report at Codecov.
|
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.
makes sense
…estjs#4520) * Display outer element and trailing newline consistently in jest-diff * Replace more with less in comment about expected result * Improve description of multiline string test * Improve comment why to append newline * Improve comment better
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
Problem 1: outer element
For example, if component changes to render a sibling element, it also returns an outer element in React 15 and earlier.
formatHunks
function makes sure that strings end with newline. Therefore, it displays an inserted (or deleted) outer element clearly:formatChunks
function doesn’t. Therefore it displays the</h1>
end tag of the original outer element unclearly as a pair of deleted and inserted lines:Problem 2: presence or absence of trailing newline
A multiline string not enclosed in quotes is hypothetical result from a plugin instead of default result from
pretty-format
package. It might become more important after #4183formatHunks
function makes sure that strings end with newline. Therefore, it displays unclearly:formatChunks
function doesn’t. Because it ignores trailing newlines at end of diffs, it displays even more unclearly:Correct and clear result for deleted (or inserted) newline:
line 1 line 2 line 3 -
Solution
Because
formatHunks
andformatChunks
ignore one trailing newline always append newline to strings.You would laugh at how much code I thought to write, before I saw that less is more :)
Test plan
Add tests to specify intended result and prevent regression: