diff --git a/read-json.js b/read-json.js index 64cc3fe..4226e77 100644 --- a/read-json.js +++ b/read-json.js @@ -469,6 +469,6 @@ function parseIndex (data) { function parseError (ex, file) { var e = new Error('Failed to parse json\n' + ex.message) e.code = 'EJSONPARSE' - e.file = file + e.path = file return e } diff --git a/test/fixtures/indexjs-bad/package.json b/test/fixtures/indexjs-bad/package.json new file mode 100644 index 0000000..71f9d30 --- /dev/null +++ b/test/fixtures/indexjs-bad/package.json @@ -0,0 +1,3 @@ +{"this is + + Not valid json!! diff --git a/test/indexjs.js b/test/indexjs.js index a98e528..1653abb 100644 --- a/test/indexjs.js +++ b/test/indexjs.js @@ -19,8 +19,9 @@ t.test('read from an index.js file', t => { }) }) -t.test('read broken json', t => { - const fixture = resolve(__dirname, 'fixtures/indexjs-bad/package.json') +t.test('missing file', t => { + // this subdirectory does not exist + const fixture = resolve(__dirname, 'fixtures/indexjs-missing/package.json') read(fixture, (er, data) => { t.match(er, { code: 'ENOENT', @@ -30,3 +31,15 @@ t.test('read broken json', t => { t.end() }) }) + +t.test('EJSONPARSE', t => { + const fixture = resolve(__dirname, 'fixtures/indexjs-bad/package.json') + read(fixture, (er, data) => { + t.match(er, { + code: 'EJSONPARSE', + path: fixture + }) + t.notOk(data) + t.end() + }) +})