From c8c4c4ec949e2b41e156734bdf4b77447d303856 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Thu, 16 Jan 2020 11:24:03 -0500 Subject: [PATCH] =?UTF-8?q?jest-snapshot:=20Fix=20regression=20in=20diff?= =?UTF-8?q?=20for=20jest-snapshot-seriali=E2=80=A6=20(#9419)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/jest-snapshot/src/printSnapshot.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/jest-snapshot/src/printSnapshot.ts b/packages/jest-snapshot/src/printSnapshot.ts index 2c73544cd1c9..72048c9e0f66 100644 --- a/packages/jest-snapshot/src/printSnapshot.ts +++ b/packages/jest-snapshot/src/printSnapshot.ts @@ -311,12 +311,18 @@ export const printSnapshotAndReceived = ( const aLines2 = a.split('\n'); const bLines2 = b.split('\n'); - const aLines0 = dedentLines(aLines2); + // Fall through to fix a regression for custom serializers + // like jest-snapshot-serializer-raw that ignore the indent option. + const b0 = serialize(received, 0); + if (b0 !== b) { + const aLines0 = dedentLines(aLines2); - if (aLines0 !== null) { - // Compare lines without indentation. - const bLines0 = serialize(received, 0).split('\n'); - return diffLinesUnified2(aLines2, bLines2, aLines0, bLines0, options); + if (aLines0 !== null) { + // Compare lines without indentation. + const bLines0 = b0.split('\n'); + + return diffLinesUnified2(aLines2, bLines2, aLines0, bLines0, options); + } } // Fall back because: