From 53c0ccc800ccdf05b7c896d8044ef12796403b77 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Wed, 23 Aug 2017 12:09:20 -0400 Subject: [PATCH] Join lines with newline in jest-diff (#4314) * Join lines with newline in jest-diff * Delete trim method and update snapshot (works with node assert) --- .../__tests__/__snapshots__/failures.test.js.snap | 6 +++--- packages/jest-diff/src/diff_strings.js | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/integration_tests/__tests__/__snapshots__/failures.test.js.snap b/integration_tests/__tests__/__snapshots__/failures.test.js.snap index 98e588e7107f..bf9554f627e8 100644 --- a/integration_tests/__tests__/__snapshots__/failures.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/failures.test.js.snap @@ -150,7 +150,7 @@ exports[`works with node assert 1`] = ` - Expected + Received - Object { + Object { \\"a\\": Object { \\"b\\": Object { - \\"c\\": 6, @@ -178,7 +178,7 @@ exports[`works with node assert 1`] = ` - Expected + Received - Object { + Object { \\"a\\": Object { \\"b\\": Object { - \\"c\\": 7, @@ -247,7 +247,7 @@ exports[`works with node assert 1`] = ` - Expected + Received - Object { + Object { - \\"a\\": 2, + \\"a\\": 1, } diff --git a/packages/jest-diff/src/diff_strings.js b/packages/jest-diff/src/diff_strings.js index 50da0c69b30f..56fbe03e3d52 100644 --- a/packages/jest-diff/src/diff_strings.js +++ b/packages/jest-diff/src/diff_strings.js @@ -71,12 +71,11 @@ const diffLines = (a: string, b: string): Diff => { .map(line => { const highlightedLine = highlightTrailingWhitespace(line, bgColor); const mark = color(part.added ? '+' : part.removed ? '-' : ' '); - return mark + ' ' + color(highlightedLine) + '\n'; + return mark + ' ' + color(highlightedLine); }) - .join(''); + .join('\n'); }) - .join('') - .trim(), + .join('\n'), isDifferent, }; }; @@ -125,17 +124,16 @@ const structuredPatch = (a: string, b: string, contextLines?: number): Diff => { const bgColor = getBgColor(added, removed); const highlightedLine = highlightTrailingWhitespace(line, bgColor); - return color(highlightedLine) + '\n'; + return color(highlightedLine); }) - .join(''); + .join('\n'); isDifferent = true; return shouldShowPatchMarks(hunk, oldLinesCount) ? createPatchMark(hunk) + lines : lines; }) - .join('') - .trim(), + .join('\n'), isDifferent, }; };