From 4f486aa6617a642f2ff6e3e6e43f5e27c4bc8388 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 f500700f9dbbb6..61746a282f5eaa 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 , in JSON at position 1$/ +); + assert.strictEqual(require('../fixtures/packages/index').ok, 'ok', 'Failed loading package'); assert.strictEqual(require('../fixtures/packages/main').ok, 'ok',