diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 8395c7dffd..20d1ccec11 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -190,6 +190,13 @@ function stringifyDiffObjs(err) { */ var generateDiff = (exports.generateDiff = function(actual, expected) { try { + const diffSize = 2048; + if (actual.length > diffSize) { + actual = actual.substring(0, diffSize) + ' ... Lines skipped'; + } + if (expected.length > diffSize) { + expected = expected.substring(0, diffSize) + ' ... Lines skipped'; + } return exports.inlineDiffs ? inlineDiff(actual, expected) : unifiedDiff(actual, expected); diff --git a/test/reporters/base.spec.js b/test/reporters/base.spec.js index 69b31d301d..cc80964668 100644 --- a/test/reporters/base.spec.js +++ b/test/reporters/base.spec.js @@ -164,6 +164,34 @@ describe('Base reporter', function() { ' \n actual expected\n \n a foobar inline diff\n ' ); }); + + it("should truncate overly long 'actual' ", function() { + var actual = ''; + var i = 0; + while (i++ < 120) { + actual += 'a foo unified diff '; + } + var expected = 'a bar unified diff'; + + inlineDiffsStub.value(false); + var output = generateDiff(actual, expected); + + expect(output, 'to match', / \.\.\. Lines skipped/); + }); + + it("should truncate overly long 'expected' ", function() { + var actual = 'a foo unified diff'; + var expected = ''; + var i = 0; + while (i++ < 120) { + expected += 'a bar unified diff '; + } + + inlineDiffsStub.value(false); + var output = generateDiff(actual, expected); + + expect(output, 'to match', / \.\.\. Lines skipped/); + }); }); describe('inline strings diff', function() {