Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
fix: avoid swallowing JSON5 error output (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobJingleheimer authored and evilebottnawi committed Mar 22, 2019
1 parent 08be680 commit d050827
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Json5Loader(source) {
try {
value = JSON5.parse(source);
} catch (e) {
throw new Error('Error parsing JSON5', (e));
this.emitError(e);
}

return `module.exports = ${util.inspect(value, { depth: null })}`;
Expand Down
11 changes: 7 additions & 4 deletions test/json5-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ describe(PROJECT_NAME, () => {
done();
});

test('should catch invalid JSON5', (done) => {
test('should handle invalid JSON5', (done) => {
const brokenJson5 = '{broken: json5}';
expect(() => {
Json5Loader.call({}, brokenJson5);
}).toThrow('Error parsing JSON5');
const emitError = jest.fn();

Json5Loader.call({
emitError,
}, brokenJson5);
expect(emitError).toHaveBeenCalledWith(expect.any(SyntaxError));
done();
});

Expand Down

0 comments on commit d050827

Please sign in to comment.