test: invalid package.json causes error when require()ing in directory
Requiring a file from a directory that contains an invalid package.json file should throw an error. PR-URL: https://github.com/nodejs/node/pull/10044 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
00ea286800
commit
4f486aa661
1
test/fixtures/packages/invalid/index.js
vendored
Normal file
1
test/fixtures/packages/invalid/index.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.ok = 'ok';
|
1
test/fixtures/packages/invalid/package.json
vendored
Normal file
1
test/fixtures/packages/invalid/package.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{,}
|
@ -69,6 +69,13 @@ assert.strictEqual(threeFolder, threeIndex);
|
||||
assert.notStrictEqual(threeFolder, three);
|
||||
|
||||
console.error('test package.json require() loading');
|
||||
assert.throws(
|
||||
function() {
|
||||
require('../fixtures/packages/invalid');
|
||||
},
|
||||
/^SyntaxError: Error parsing \S+: Unexpected token , in JSON at position 1$/
|
||||
);
|
||||
|
||||
assert.strictEqual(require('../fixtures/packages/index').ok, 'ok',
|
||||
'Failed loading package');
|
||||
assert.strictEqual(require('../fixtures/packages/main').ok, 'ok',
|
||||
|
Loading…
x
Reference in New Issue
Block a user