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

Commit d050827

Browse files
JakobJingleheimerevilebottnawi
authored andcommitted
fix: avoid swallowing JSON5 error output (#34)
1 parent 08be680 commit d050827

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Diff for: src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Json5Loader(source) {
1212
try {
1313
value = JSON5.parse(source);
1414
} catch (e) {
15-
throw new Error('Error parsing JSON5', (e));
15+
this.emitError(e);
1616
}
1717

1818
return `module.exports = ${util.inspect(value, { depth: null })}`;

Diff for: test/json5-loader.test.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ describe(PROJECT_NAME, () => {
1515
done();
1616
});
1717

18-
test('should catch invalid JSON5', (done) => {
18+
test('should handle invalid JSON5', (done) => {
1919
const brokenJson5 = '{broken: json5}';
20-
expect(() => {
21-
Json5Loader.call({}, brokenJson5);
22-
}).toThrow('Error parsing JSON5');
20+
const emitError = jest.fn();
21+
22+
Json5Loader.call({
23+
emitError,
24+
}, brokenJson5);
25+
expect(emitError).toHaveBeenCalledWith(expect.any(SyntaxError));
2326
done();
2427
});
2528

0 commit comments

Comments
 (0)