Skip to content

Commit af44dd4

Browse files
authored
feat: better error message (#254)
1 parent 550f37a commit af44dd4

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

__tests__/diff-snapshot.spec.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,30 @@ describe('diff-snapshot', () => {
5050
expect(mockSpawnSync).toBeCalled();
5151
});
5252

53-
it('throws when process returns a non-zero status', () => {
54-
const runDiffImageToSnapshot = setupTest({ status: 1 });
55-
expect(() => runDiffImageToSnapshot(fakeRequest)).toThrow();
53+
it.each`
54+
spawnReturn
55+
${{ status: 1 }}
56+
${{ status: 1, error: {} }}
57+
${{ status: 1, error: new Error() }}
58+
`(
59+
'throws an Unknown Error when process returns a non-zero status $#',
60+
({ spawnReturn }) => {
61+
const runDiffImageToSnapshot = setupTest(spawnReturn);
62+
63+
expect(() => runDiffImageToSnapshot(fakeRequest)).toThrowError(
64+
new Error('Error running image diff: Unknown Error')
65+
);
66+
}
67+
);
68+
69+
it('throws a helpful error if available', () => {
70+
const runDiffImageToSnapshot = setupTest({
71+
status: 1,
72+
error: new Error('🦖'),
73+
});
74+
expect(() => runDiffImageToSnapshot(fakeRequest)).toThrowError(
75+
new Error('Error running image diff: 🦖')
76+
);
5677
});
5778
});
5879

src/diff-snapshot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ function runDiffImageToSnapshot(options) {
343343
const output = writeDiffProcess.output[3].toString();
344344
result = JSON.parse(output);
345345
} else {
346-
throw new Error('Error running image diff.');
346+
throw new Error(`Error running image diff: ${(writeDiffProcess.error && writeDiffProcess.error.message) || 'Unknown Error'}`);
347347
}
348348

349349
return result;

0 commit comments

Comments
 (0)