diff --git a/src/index.js b/src/index.js index d654d95..ebbae93 100644 --- a/src/index.js +++ b/src/index.js @@ -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 })}`; diff --git a/test/json5-loader.test.js b/test/json5-loader.test.js index e1199fb..3bb5fd6 100644 --- a/test/json5-loader.test.js +++ b/test/json5-loader.test.js @@ -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(); });