Skip to content

Commit

Permalink
fix: only exit with 1 when differences are written
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvanderlinden committed Sep 14, 2020
1 parent d205b5e commit a125514
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`))
Expand All @@ -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)}`))
Expand All @@ -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) {
Expand Down

0 comments on commit a125514

Please sign in to comment.