Skip to content

Commit

Permalink
Always omit at least two lines in string diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 1, 2019
1 parent bf6dd37 commit eba60ba
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/styles.js
Expand Up @@ -203,9 +203,7 @@ module.exports = expect => {
});

expect.addStyle('diffLinesOmitted', function(lineCount) {
this.jsComment(
`... ${lineCount} line${lineCount === 1 ? '' : 's'} omitted ...`
);
this.jsComment(`... ${lineCount} lines omitted ...`);
});

expect.addStyle('removedHighlight', function(content) {
Expand Down Expand Up @@ -471,7 +469,7 @@ module.exports = expect => {
);
} else {
const horizon = 3;
if (index === diffLines.length - 1 && part.count > horizon) {
if (index === diffLines.length - 1 && part.count > horizon + 1) {
this.stringDiffFragment(
' ',
value
Expand All @@ -482,7 +480,7 @@ module.exports = expect => {
)
.nl()
.diffLinesOmitted(part.count - horizon);
} else if (index === 0 && part.count > horizon) {
} else if (index === 0 && part.count > horizon + 1) {
this.diffLinesOmitted(part.count - horizon)
.nl()
.stringDiffFragment(
Expand All @@ -493,7 +491,7 @@ module.exports = expect => {
.join('\n'),
'text'
);
} else if (part.count > 2 * horizon) {
} else if (part.count > 2 * horizon + 1) {
this.stringDiffFragment(
' ',
value
Expand Down
33 changes: 33 additions & 0 deletions test/assertions/to-be.spec.js
Expand Up @@ -146,6 +146,39 @@ describe('to be assertion', () => {
);
});

// These would be annoying to look at
it('does not produce ... 1 lines omitted ... lines', () => {
expect(
() =>
expect(
'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\n',
'to equal',
'a\nb\nc\nd\nf\ng\nh\ni\nj\nk\nl\nn\no\np\nq\n'
),
'to throw',
"expected 'a\\nb\\nc\\nd\\ne\\nf\\ng\\nh\\ni\\nj\\nk\\nl\\nm\\nn\\no\\np\\nq\\n'\n" +
"to equal 'a\\nb\\nc\\nd\\nf\\ng\\nh\\ni\\nj\\nk\\nl\\nn\\no\\np\\nq\\n'\n" +
'\n' +
' a\n' +
' b\n' +
' c\n' +
' d\n' +
'-e\n' +
' f\n' +
' g\n' +
' h\n' +
' i\n' +
' j\n' +
' k\n' +
' l\n' +
'-m\n' +
' n\n' +
' o\n' +
' p\n' +
' q\n'
);
});

it('truncates lines in large in the start and end', () => {
const paragraphs = `\
Bacon ipsum dolor amet tri-tip kielbasa kevin spare ribs. Sirloin chuck jerky
Expand Down

0 comments on commit eba60ba

Please sign in to comment.