From e7c4dfb83b32d6ffb564282326dec23f2226c627 Mon Sep 17 00:00:00 2001 From: Sam Shull Date: Thu, 1 Dec 2016 09:55:07 -0800 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/fixtures/packages/invalid/index.js | 1 + test/fixtures/packages/invalid/package.json | 1 + test/sequential/test-module-loading.js | 7 +++++++ 3 files changed, 9 insertions(+) create mode 100644 test/fixtures/packages/invalid/index.js create mode 100644 test/fixtures/packages/invalid/package.json diff --git a/test/fixtures/packages/invalid/index.js b/test/fixtures/packages/invalid/index.js new file mode 100644 index 00000000000000..014fa39dc365d1 --- /dev/null +++ b/test/fixtures/packages/invalid/index.js @@ -0,0 +1 @@ +exports.ok = 'ok'; diff --git a/test/fixtures/packages/invalid/package.json b/test/fixtures/packages/invalid/package.json new file mode 100644 index 00000000000000..004e1e20324524 --- /dev/null +++ b/test/fixtures/packages/invalid/package.json @@ -0,0 +1 @@ +{,} diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js index 2f4a85748ec03e..6125eefc360f00 100644 --- a/test/sequential/test-module-loading.js +++ b/test/sequential/test-module-loading.js @@ -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 ,$/ +); + assert.strictEqual(require('../fixtures/packages/main').ok, 'ok', 'Failed loading package'); assert.strictEqual(require('../fixtures/packages/main-index').ok, 'ok',