-
Notifications
You must be signed in to change notification settings - Fork 23
feat: add stablePatchmarks option #72
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
Changes from 1 commit
da0826c
4128a9e
c987028
5eae495
81a2e9a
93f451b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,8 @@ expect(valueA: any).toMatchDiffSnapshot(valueB: any, options?: Options, testName | |
- `expand: boolean` (default: `false`) – expand the diff, so the whole information is preserved | ||
- `colors: boolean` (default: `false`) – preserve color information from Jest diff | ||
- `contextLines: number` (default: 5) - number of context lines to be shown at the beginning and at the end of a snapshot | ||
- `omitPatchMarks: boolean` (default: `false`) - prevent line number patch marks from appearing in | ||
diffs. This can be helpful when diffs are breaking only because of the patch marks. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would also be cool to show an example like: changes @@ -1,1 +1,2 @@ to @@ --- --- @ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
- `aAnnotation: string` (default: `'First Value'`) - the annotation indicating from which serialization the `-` lines are | ||
- `bAnnotation: string` (default: `'Second Value'`) - the annotation indicating from which serialization the `+` lines are | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ const defaultOptions = { | |
expand: false, | ||
colors: false, | ||
contextLines: -1, // Forces to use default from Jest | ||
omitPatchMarks: false, | ||
aAnnotation: 'First value', | ||
bAnnotation: 'Second value', | ||
}; | ||
|
@@ -43,6 +44,10 @@ const snapshotDiff = (valueA: any, valueB: any, options?: Options): string => { | |
difference = stripAnsi(difference); | ||
} | ||
|
||
if (mergedOptions.omitPatchMarks) { | ||
difference = difference.replace(/^@.*/gm, '-------------') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can make this regex better and take into account that we have two @@ and numbers with commas between. Also I'm leaning towards replacing them with: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we only need to check it only if expand === false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered a more rigorous regex, but since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, left out the 0s in the number range. Updated regex: https://regex101.com/r/KLDkC0/2 |
||
} | ||
|
||
return SNAPSHOT_TITLE + difference; | ||
}; | ||
|
||
|
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.
How about
stablePatchmarks
? I'm still not sure how to best me it. @SimenB ideas?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.
stable
is better thanomit
. Other possible verbs:normalize
scrub
normalize
doesn't communicate a whole lot.scrub
communicates what we are doing to the patch mark, whilestable
communicates the purpose behind it.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 think I'd still go with
stable
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.
all set