Skip to content

Commit

Permalink
test: add module require tests for certain package.json errors
Browse files Browse the repository at this point in the history
test for unusual error cases: verify that module require()
falls back to index if package.json names a missing file and
throws an error if package.json is unparseable.

PR-URL: #23285
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
TomCoded authored and targos committed Oct 10, 2018
1 parent 9749d48 commit b523f13
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/fixtures/packages/missing-main/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

exports.ok = 'ok';
4 changes: 4 additions & 0 deletions test/fixtures/packages/missing-main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "missingmain",
"main": "doesnotexist.js"
}
3 changes: 3 additions & 0 deletions test/fixtures/packages/unparseable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "therain" "inspain"
}
7 changes: 7 additions & 0 deletions test/sequential/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ const d2 = require('../fixtures/b/d');
assert.strictEqual(require('../fixtures/packages/index').ok, 'ok');
assert.strictEqual(require('../fixtures/packages/main').ok, 'ok');
assert.strictEqual(require('../fixtures/packages/main-index').ok, 'ok');
assert.strictEqual(require('../fixtures/packages/missing-main').ok, 'ok');

assert.throws(
function() { require('../fixtures/packages/unparseable'); },
/^SyntaxError: Error parsing/
);

{
console.error('test cycles containing a .. path');
Expand Down Expand Up @@ -267,6 +273,7 @@ try {
'fixtures/packages/index/index.js': {},
'fixtures/packages/main/package-main-module.js': {},
'fixtures/packages/main-index/package-main-module/index.js': {},
'fixtures/packages/missing-main/index.js': {},
'fixtures/cycles/root.js': {
'fixtures/cycles/folder/foo.js': {}
},
Expand Down

0 comments on commit b523f13

Please sign in to comment.