-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jest-snapshot: Highlight substring differences when matcher fails, pa…
…rt 3 (#8569) * expect: Highlight substring differences when matcher fails, part 3 * Delete duplicate line comment slashes * Update CHANGELOG.md * Remove backslash escape preceding backslash * Replace expect with jest-snapshot in CHANGELOG.md * Delete unnecessary isExpand function * Factor out printDiffOrStringified into added print.ts file * Add unit tests for printDiffOrStringified function * Add Facebook comment to 2 added files * Fix two edge cases * Fall back to line diff if either serialization has newline * Also display diff if strings have application-specific serialization * Add test without serialize * Edit comments for consistent use of serialization versus stringified * Call getStringDiff when strings have custom serialization * Edit comment * Add tests for backtick and isLineDiffable true single-multi
- Loading branch information
1 parent
fe14493
commit 6fbcd9e
Showing
10 changed files
with
778 additions
and
27 deletions.
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.