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

Avoid swallowing JSON5 error output #34

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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