From a1255140fb54a37bd259e919ea6be5ddd309a8df Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Mon, 14 Sep 2020 16:41:13 +0200 Subject: [PATCH] fix: only exit with 1 when differences are written --- src/diff.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/diff.js b/src/diff.js index f302d74..48a5dcd 100644 --- a/src/diff.js +++ b/src/diff.js @@ -71,11 +71,13 @@ async function diff(input1, input2, options) { (entriesByRequestId) => entriesByRequestId[requestId] || [] ) ); + let foundDifference = false; const unmatchingPairs = pairs.filter( ([entry1, entry2]) => !Object.is(entry1, entry2) ); for (const [entry1, entry2] of unmatchingPairs) { if (entry1.length === 0 || entry2.length === 0) { + foundDifference = true; console.log( [`--- ${input1}`, `+++ ${input2}`] .concat(entry1.map((entry) => `-- ${stringifyEntry(entry, options)}`)) @@ -92,6 +94,7 @@ async function diff(input1, input2, options) { if (diffString.includes("Compared values have no visual difference.")) { continue; } + foundDifference = true; console.log( [`--- ${input1}`, `+++ ${input2}`] .concat(entry1.map((entry) => `-- ${stringifyEntry(entry)}`)) @@ -103,7 +106,7 @@ async function diff(input1, input2, options) { } // Set exitCode to failure if there are differences between inputs. - process.exitCode = unmatchingPairs.length > 0 ? 1 : 0; + process.exitCode = foundDifference ? 1 : 0; } function defineCommand(program) {