Jest: Collapse big diffs by default

Created on 17 Sep 2016  路  9Comments  路  Source: facebook/jest

Both for snapshots and regular diffs in other matchers, the diffs often get unwieldy and huge. Let's find a good heuristic to collapse unimportant info by default and add an -e (--expand) flag to print the full diff. It should be intentionally different from --verbose.

Proposed heuristic:

  • Always print small diffs, collapse unimportant diffs over N lines automatically
  • Always print small diffs, collapse unimportant changes based on the ratio between changed/unchanged lines. If there is a high ratio of changed lines, show all changes.
  • ...?
Enhancement Help Wanted good first issue

All 9 comments

a couple of thoughts:

  • it's important to always print full diffs when running in CI mode.
  • if we implement interactive snapshot updates, we can always show small diffs and then give an option to expand (press 'e' to expand snapshot diffs)

if we implement interactive snapshot updates, we can always show small diffs and then give an option to expand (press 'e' to expand snapshot diffs)

馃憤

If use with in watch mode --watch it could led to an interactive mode close of git stash --patch. It will allow the developer to browse interactively each change and validate each one separately. On each diff the developer could chose between: show next/previous diff, expand, update snapshot, ignore.

@cpojer I wonder if something like this would suffice?

screen shot 2016-10-07 at 00 13 51

@thymikee yeah that looks great! Why @@? Is that what other diff tools do?

Yup, this is what my git diff tool output looks like, but it shows line number near the change.

Since snapshots are not showing any information about line number, I thought counting the trimmed lines would be just nice to have.

screen shot 2016-10-07 at 08 39 08

Yeah I think this is nice! Are you going to send us a PR? :)

I think we should keep 4 lines of context at least.

Sure, done!

We'll continue the conversation in the PR.

Was this page helpful?
0 / 5 - 0 ratings