From 1586b87f1a371c6a94ec07819b5e5df280199753 Mon Sep 17 00:00:00 2001 From: juergba Date: Mon, 24 May 2021 11:38:37 +0200 Subject: [PATCH 1/2] diff: truncate long actual/expected strings --- lib/reporters/base.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 8782f64914..ffdd1699af 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); From af3b2a8e7e158c6ef9f8978784948d968c7f9220 Mon Sep 17 00:00:00 2001 From: juergba Date: Mon, 24 May 2021 11:38:49 +0200 Subject: [PATCH 2/2] tests --- test/reporters/base.spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/reporters/base.spec.js b/test/reporters/base.spec.js index e8e0a782e9..b61dfb1ecf 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() {