summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Shull <sam+github@samshull.com>2016-12-01 09:55:07 -0800
committerItalo A. Casas <me@italoacasas.com>2016-12-07 10:00:11 -0500
commit4f486aa6617a642f2ff6e3e6e43f5e27c4bc8388 (patch)
tree6f52c35f2914e081b3d86f153cfa5e6094df06f6
parent00ea28680058d7632cb21b270efa561116a7afa7 (diff)
downloadandroid-node-v8-4f486aa6617a642f2ff6e3e6e43f5e27c4bc8388.tar.gz
android-node-v8-4f486aa6617a642f2ff6e3e6e43f5e27c4bc8388.tar.bz2
android-node-v8-4f486aa6617a642f2ff6e3e6e43f5e27c4bc8388.zip
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>
-rw-r--r--test/fixtures/packages/invalid/index.js1
-rw-r--r--test/fixtures/packages/invalid/package.json1
-rw-r--r--test/sequential/test-module-loading.js7
3 files changed, 9 insertions, 0 deletions
diff --git a/test/fixtures/packages/invalid/index.js b/test/fixtures/packages/invalid/index.js
new file mode 100644
index 0000000000..014fa39dc3
--- /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 0000000000..004e1e2032
--- /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 f500700f9d..61746a282f 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',