Skip to content

Commit

Permalink
Join lines with newline in jest-diff (#4314)
Browse files Browse the repository at this point in the history
* Join lines with newline in jest-diff

* Delete trim method and update snapshot (works with node assert)
  • Loading branch information
pedrottimark authored and cpojer committed Aug 23, 2017
1 parent 0679853 commit 53c0ccc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ exports[`works with node assert 1`] = `
- Expected
+ Received
Object {
Object {
\\"a\\": Object {
\\"b\\": Object {
- \\"c\\": 6,
Expand Down Expand Up @@ -178,7 +178,7 @@ exports[`works with node assert 1`] = `
- Expected
+ Received
Object {
Object {
\\"a\\": Object {
\\"b\\": Object {
- \\"c\\": 7,
Expand Down Expand Up @@ -247,7 +247,7 @@ exports[`works with node assert 1`] = `
- Expected
+ Received
Object {
Object {
- \\"a\\": 2,
+ \\"a\\": 1,
}
Expand Down
14 changes: 6 additions & 8 deletions packages/jest-diff/src/diff_strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
Expand Down Expand Up @@ -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,
};
};
Expand Down

0 comments on commit 53c0ccc

Please sign in to comment.