Skip to content

Commit

Permalink
feat: better error message (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle authored Feb 26, 2021
1 parent 550f37a commit af44dd4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions __tests__/diff-snapshot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,30 @@ describe('diff-snapshot', () => {
expect(mockSpawnSync).toBeCalled();
});

it('throws when process returns a non-zero status', () => {
const runDiffImageToSnapshot = setupTest({ status: 1 });
expect(() => runDiffImageToSnapshot(fakeRequest)).toThrow();
it.each`
spawnReturn
${{ status: 1 }}
${{ status: 1, error: {} }}
${{ status: 1, error: new Error() }}
`(
'throws an Unknown Error when process returns a non-zero status $#',
({ spawnReturn }) => {
const runDiffImageToSnapshot = setupTest(spawnReturn);

expect(() => runDiffImageToSnapshot(fakeRequest)).toThrowError(
new Error('Error running image diff: Unknown Error')
);
}
);

it('throws a helpful error if available', () => {
const runDiffImageToSnapshot = setupTest({
status: 1,
error: new Error('🦖'),
});
expect(() => runDiffImageToSnapshot(fakeRequest)).toThrowError(
new Error('Error running image diff: 🦖')
);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/diff-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ function runDiffImageToSnapshot(options) {
const output = writeDiffProcess.output[3].toString();
result = JSON.parse(output);
} else {
throw new Error('Error running image diff.');
throw new Error(`Error running image diff: ${(writeDiffProcess.error && writeDiffProcess.error.message) || 'Unknown Error'}`);
}

return result;
Expand Down

0 comments on commit af44dd4

Please sign in to comment.