-
-
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-snapshot: Highlight substring differences when matcher fails, part 3 #8569
Merged
pedrottimark
merged 17 commits into
jestjs:master
from
pedrottimark:highlight-substring-3
Jun 18, 2019
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fe6a6cd
expect: Highlight substring differences when matcher fails, part 3
pedrottimark e7c5399
Delete duplicate line comment slashes
pedrottimark 3c91975
Update CHANGELOG.md
pedrottimark b9897cb
Remove backslash escape preceding backslash
pedrottimark 5e3009a
Replace expect with jest-snapshot in CHANGELOG.md
pedrottimark 31b142e
Delete unnecessary isExpand function
pedrottimark f3ce45e
Factor out printDiffOrStringified into added print.ts file
pedrottimark 30722ad
Add unit tests for printDiffOrStringified function
pedrottimark 671c633
Add Facebook comment to 2 added files
pedrottimark 1da96c1
Fix two edge cases
pedrottimark ce92ea4
Fall back to line diff if either serialization has newline
pedrottimark 830f6af
Also display diff if strings have application-specific serialization
pedrottimark 71dc81f
Add test without serialize
pedrottimark 76205f9
Edit comments for consistent use of serialization versus stringified
pedrottimark 32aedff
Call getStringDiff when strings have custom serialization
pedrottimark d3f0791
Edit comment
pedrottimark fc564ac
Add tests for backtick and isLineDiffable true single-multi
pedrottimark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 230 additions & 0 deletions
230
packages/jest-snapshot/src/__tests__/__snapshots__/printDiffOrStringified.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`backtick single line expected and received 1`] = ` | ||
Snapshot: <g>"var foo = \`backtick\`;"</> | ||
Received: <r>"var foo = <i>tag</i>\`backtick\`;"</> | ||
`; | ||
|
||
exports[`empty string expected and received single line 1`] = ` | ||
Snapshot: <g>""</> | ||
Received: <r>"single line string"</> | ||
`; | ||
|
||
exports[`empty string received and expected multi line 1`] = ` | ||
Snapshot: <g>"multi</> | ||
<g>line</> | ||
<g>string"</> | ||
Received: <r>""</> | ||
`; | ||
|
||
exports[`escape backslash in multi line string 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<g>- Forward / slash<i> and b</i>ack \\ slash</> | ||
<r>+ Forward / slash</> | ||
<r>+ <i>B</i>ack \\ slash</> | ||
`; | ||
|
||
exports[`escape backslash in single line string 1`] = ` | ||
Snapshot: <g>"<i>f</i>orward / slash and back \\\\ slash"</> | ||
Received: <r>"<i>F</i>orward / slash and back \\\\ slash"</> | ||
`; | ||
|
||
exports[`escape double quote marks in string 1`] = ` | ||
Snapshot: <g>"What does \\"<i>oo</i>bleck\\" mean?"</> | ||
Received: <r>"What does \\"<i>ew</i>bleck\\" mean?"</> | ||
`; | ||
|
||
exports[`escape regexp 1`] = ` | ||
Snapshot: <g>/\\\\\\\\\\("\\)/g</> | ||
Received: <r>/\\\\\\\\\\("\\)/</> | ||
`; | ||
|
||
exports[`expand false 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<y>@@ -12,7 +12,9 @@</> | ||
<d> ? "number"</> | ||
<d> : T extends boolean</> | ||
<d> ? "boolean"</> | ||
<d> : T extends undefined</> | ||
<d> ? "undefined"</> | ||
<g>- : T extends Function<i> </i>? "function"<i> </i>: "object";</> | ||
<r>+ : T extends Function</> | ||
<r>+ ? "function"</> | ||
<r>+ : "object";</> | ||
<d> ↵</> | ||
`; | ||
|
||
exports[`expand true 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<d> type TypeName<T> =</> | ||
<d> T extends string ? "string" :</> | ||
<d> T extends number ? "number" :</> | ||
<d> T extends boolean ? "boolean" :</> | ||
<d> T extends undefined ? "undefined" :</> | ||
<d> T extends Function ? "function" :</> | ||
<d> "object";</> | ||
<d> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</> | ||
<d> type TypeName<T> = T extends string</> | ||
<d> ? "string"</> | ||
<d> : T extends number</> | ||
<d> ? "number"</> | ||
<d> : T extends boolean</> | ||
<d> ? "boolean"</> | ||
<d> : T extends undefined</> | ||
<d> ? "undefined"</> | ||
<g>- : T extends Function<i> </i>? "function"<i> </i>: "object";</> | ||
<r>+ : T extends Function</> | ||
<r>+ ? "function"</> | ||
<r>+ : "object";</> | ||
<d> ↵</> | ||
`; | ||
|
||
exports[`fallback to line diff 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<r>+ ====================================options=====================================</> | ||
<r>+ parsers: ["flow", "typescript"]</> | ||
<r>+ printWidth: 80</> | ||
<r>+ | printWidth</> | ||
<r>+ =====================================input======================================</> | ||
<d> [...a, ...b,];</> | ||
<d> [...a, ...b];</> | ||
<g>- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</> | ||
<r>+ </> | ||
<r>+ =====================================output=====================================</> | ||
<d> [...a, ...b];</> | ||
<d> [...a, ...b];</> | ||
<d> </> | ||
<r>+ ================================================================================</> | ||
`; | ||
|
||
exports[`isLineDiffable false boolean 1`] = ` | ||
Snapshot: <g>true</> | ||
Received: <r>false</> | ||
`; | ||
|
||
exports[`isLineDiffable false number 1`] = ` | ||
Snapshot: <g>-0</> | ||
Received: <r>NaN</> | ||
`; | ||
|
||
exports[`isLineDiffable true array 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<d> Array [</> | ||
<d> Object {</> | ||
<r>+ "_id": "b14680dec683e744ada1f2fe08614086",</> | ||
<d> "code": 4011,</> | ||
<d> "weight": 2.13,</> | ||
<d> },</> | ||
<d> Object {</> | ||
<r>+ "_id": "7fc63ff01769c4fa7d9279e97e307829",</> | ||
<d> "code": 4019,</> | ||
<d> "count": 4,</> | ||
<d> },</> | ||
<d> ]</> | ||
`; | ||
|
||
exports[`isLineDiffable true object 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<d> Object {</> | ||
<d> "props": Object {</> | ||
<g>- "className": "logo",</> | ||
<g>- "src": "/img/jest.png",</> | ||
<r>+ "alt": "Jest logo",</> | ||
<r>+ "class": "logo",</> | ||
<r>+ "src": "/img/jest.svg",</> | ||
<d> },</> | ||
<d> "type": "img",</> | ||
<d> }</> | ||
`; | ||
|
||
exports[`isLineDiffable true single line expected and multi line received 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<g>- Array []</> | ||
<r>+ Array [</> | ||
<r>+ 0,</> | ||
<r>+ ]</> | ||
`; | ||
|
||
exports[`isLineDiffable true single line expected and received 1`] = ` | ||
Snapshot: <g>Array []</> | ||
Received: <r>Object {}</> | ||
`; | ||
|
||
exports[`multi line small change in one line and other is unchanged 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<g>- There is no route defined for key <i>'</i>Settings<i>'</i>.</> | ||
<r>+ There is no route defined for key Settings.</> | ||
<d> Must be one of: 'Home'</> | ||
`; | ||
|
||
exports[`multi line small changes 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<g>- 6<i>9</i> |·</> | ||
<r>+ 6<i>8</i> |·</> | ||
<g>- <i>70</i> | test('assert.doesNotThrow', () => {</> | ||
<r>+ <i>69</i> | test('assert.doesNotThrow', () => {</> | ||
<g>- > 7<i>1</i> | assert.doesNotThrow(() => {</> | ||
<r>+ > 7<i>0</i> | assert.doesNotThrow(() => {</> | ||
<d> | ^</> | ||
<g>- 7<i>2</i> | throw Error('err!');</> | ||
<r>+ 7<i>1</i> | throw Error('err!');</> | ||
<g>- 7<i>3</i> | });</> | ||
<r>+ 7<i>2</i> | });</> | ||
<g>- 7<i>4</i> | });</> | ||
<r>+ 7<i>3</i> | });</> | ||
<g>- at Object.doesNotThrow (__tests__/assertionError.test.js:7<i>1</i>:10)</> | ||
<r>+ at Object.doesNotThrow (__tests__/assertionError.test.js:7<i>0</i>:10)</> | ||
`; | ||
|
||
exports[`single line large changes 1`] = ` | ||
Snapshot: <g>"<i>A</i>rray length<i> must be a finite positive integer</i>"</> | ||
Received: <r>"<i>Invalid a</i>rray length"</> | ||
`; | ||
|
||
exports[`without serialize backtick single line expected and multi line received 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<g>- var foo = \`backtick\`;</> | ||
<r>+ var foo = \`back</> | ||
<r>+ tick\`;</> | ||
`; | ||
|
||
exports[`without serialize backtick single line expected and received 1`] = ` | ||
Snapshot: <g>var foo = \`backtick\`;</> | ||
Received: <r>var foo = \`back<i>\${x}</i>tick\`;</> | ||
`; | ||
|
||
exports[`without serialize prettier/pull/5590 1`] = ` | ||
<g>- Snapshot</> | ||
<r>+ Received</> | ||
|
||
<y>@@ -4,8 +4,8 @@</> | ||
<d> | printWidth</> | ||
<d> =====================================input======================================</> | ||
<d> <img src="test.png" alt='John "ShotGun" Nelson'></> | ||
|
||
<d> =====================================output=====================================</> | ||
<g>- <img src="test.png" alt=<i>"</i>John <i>"</i>ShotGun<i>"</i> Nelson<i>"</i> /></> | ||
<r>+ <img src="test.png" alt=<i>'</i>John <i>"</i>ShotGun<i>"</i> Nelson<i>'</i> /></> | ||
|
||
<d> ================================================================================</> | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In the empty/multiline case, maybe start the multiline string on the next line so that the indentation is less off (still off by one because of 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.
Super question, as usual. Extra credit for thinking about alignment.
Here are 2 alternatives for response or maybe they provoke some other solution:
I though about omitting double quote marks, but content of string might be ambiguous with serialization of other data types.
I’m thinking backticks for multiline string property in future data-driven diff at right:
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.
Second one is probably easier on the eyes if the string itself has lines indented by 2. Wondering if inserting indentation into people's strings is a good idea though - is there a legitimate use case for copying it out of the terminal?
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.
Yes, inserting indentation is a concern. Although Jest indents the reports in console.
Of alternatives above, I agree with you to prefer at the right.
Here is the minimal solution at the left and another indented alternative at the right:
Unless there is a clear winner, I think to leave it alone (as it has been) for this pull request.