-
-
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: Replace diff with diff-sequences package #6961
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6961 +/- ##
=========================================
+ Coverage 66.86% 67% +0.13%
=========================================
Files 250 250
Lines 10460 10510 +50
Branches 3 3
=========================================
+ Hits 6994 7042 +48
- Misses 3465 3467 +2
Partials 1 1
Continue to review full report at Codecov.
|
Wooooooo! I've been waiting for this! 😀
React also uses |
CHANGELOG.md
Outdated
@@ -1,5 +1,9 @@ | |||
## master | |||
|
|||
### Features | |||
|
|||
- `[jest-diff]` Replace `diff` with `diff-sequences` package ([#6961](https://github.com/facebook/jest/pull/6961)) |
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.
Add **Breaking**
as well if it is? 🙂
Also, is this a pure performance change or is the visual output for users different? If the latter, mind adding some screenshots? EDIT: nvm, I just red your OP more thoroughly, and you've included some example, which both makes perfect sense 🙂 |
Goal for this pull request is improve performance. A separate pull request #6917 explains in The formatting remains the same, so most dependents which use |
To answer your question about React, here is what I did:
|
Thanks for the heads up! I'll take this into account when I bump the dependencies. |
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.
I just had a quick glance, so I left some nits. Can you share any perf numbers for smaller and larger diffs? Does it affect overall perf of our suite for example?
aStart: number, | ||
aEnd: number, | ||
aLinesUn: Array<string>, | ||
aLinesIn: Array<string>, |
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 we change the variables names?
aStart -> start
aLinesUn -> linesUnchanged
etc
This comment is valid for all names like these (except when it makes sense where you have a,b related args)
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.
I will review naming and think how to improve comments here to make it less surprising.
The reason for a
prefix in formatDelete
and b
prefix in formatInsert
is to remind me assumption or convention that took me a while to understand:
- differences in expected value are always formatted as deleted
- differences in received value are always formatted as inserted
const fgDelete = chalk.green; | ||
const fgInsert = chalk.red; | ||
const fgUnchanged = chalk.dim; // common lines (even indentation same) | ||
const fgInchanged = chalk.cyan; // common lines (only indentation different) |
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.
fgIndent maybe? Inchanged sounds weird
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.
replace | with |
---|---|
fgUnchanged |
fgCommon |
fgInchanged |
fgIndent |
bgUnchanged |
bgCommon |
bgDefault |
bgInverse |
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.
I like those suggestions!
Might be a good idea to create a performance suite for this, similar to https://github.com/facebook/jest/tree/master/packages/pretty-format/perf (although I would prefer it to be written in https://github.com/bestiejs/benchmark.js/ or something and not something home cooked) |
@thymikee A performance suite in The problem solved by replacing
@SimenB Thank you for suggesting I will convert perf test for |
Got a PR using |
Btw, #4619 is back on the table after this is merged, right? |
CHANGELOG.md
Outdated
@@ -1,5 +1,9 @@ | |||
## master | |||
|
|||
### Features | |||
|
|||
- Breaking Change: `[jest-diff]` Replace `diff` with `diff-sequences` package ([#6961](https://github.com/facebook/jest/pull/6961)) |
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 use the format:
- `[jest-diff]` [**BREAKING**] blablabla
I'm having this problem #1772 (comment) ... do you think I can solve it after this PR is merged? .. or do you think I can install jest from the fork so I can experiment with it ? |
Feel free to play with it :) |
@pedrottimark any news on that benchmark? :) I think we're good to land as soon as those are in place Also, semi related: prettier/prettier#4816 |
I played with this PR in my project and apparently it feels faster than 23.6.0, having snapshots > 1MB |
@hisapy Why not |
That's a good idea. Too bad I didn't think of it before trying this fork. I was in a real hurry and I just wanted to Just for the record, I first tried to Finally, after some checks I would've done before chasing the error in jest, I realized that my snapshot tests were failing because I had some snapshots with really huge sizes (35MB, 13MB being the largest) so I came with strategy of splitting the snapshots in multiple files and now the largest are at most ~1.4MB, which run just fine. I hope I can fix some other stuff quickly so I can |
I will work on performance benchmark over the week end. |
@canemacchina we've already landed breaking changes in master (and this is a breaking change in and of itself), so this won't be released before Jest 24. Sorry! |
Oh... Well, I'll wait! Thanks anyway! |
This would be really appreciated addition as I'm having hanging tests with storyshots which is using snapshots under the hood. |
@rubennorte could you run this diff on fb and see if either functionality or performance regresses? |
@rickhanlonii maybe you can? |
@pedrottimark mind resolving conflicts? |
@rubennorte @rickhanlonii we'd appreciate testing this at FB scale. For now I feel like we're ready to merge it |
Think of small changes to cause |
* jest-diff: Replace diff with diff-sequences package * Update CHANGELOG.md * Add Breaking Change in CHANGELOG.md * Rename 4 variables for chalk colors
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
Fixes #1772 #5392 besser spät als nie :)
Much faster when number of changed lines is large: less memory and fewer iterations.
The baseline and improved versions report the same number of changed versus common lines.
This a breaking change from viewpoint of dependents like
snapshot-diff
orsnapshot-diff-serializer
package which use output ofjest-diff
as a test criterion instead of a report./cc @thymikee @wldcordeiro
Given received and expected values, the improved version can return different particular lines as inserted, deleted, or common than the baseline version (especially for swapped lines, see below).
In case you ask why different particular lines, because
diff-sequences
can often return 2 differences per bisection to minimize depth of recursive calls, it might find alternative path in edit graph.The tests for
snapshot-diff
still pass.For realistic differences of
.js
,.json
,.md
, and.snap
files, only 12.2% = 1259 / 10306 had exactly the samechangedoutput in offline comparison of baseline to improved versions ofjest-diff
in the 2000 commits going back in history from Jest 23.5.0.For
--expand
option, the improved code is based on documentation:https://github.com/facebook/jest/tree/master/packages/diff-sequences#example-of-callback-functions-to-format-diff-lines
For default
--no-expand
option, thefoundSubsequences
callback function emulates the hunk and patch logic fromdiff
package: application-specific logic moves intojest-diff
package.By the way, Jest still has
diff
as a dependence:Test plan
Updated 6 snapshots for
collapses big diffs to patch format
andcontext
tests:Expected:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Received:
[1, 2, 3, 4, 5, 6, 7, 8, 10, 9]
Differences in baseline version, that is, 10 is change, 9 is common:
Differences in improved version, that is, 9 is change, 10 is common:
Updated 4 snapshots in
matchers.test.js
ofexpect
package:Expected:
[2, 1]
or{2: "two", 1: "one"}
Received:
[1, 2]
or{1: "one", 2: "two"}
Differences in baseline version, that is, 1 is change, 2 is common:
Differences in improved version, that is, 2 is change, 1 is common: