Skip to content

Commit b523f13

Browse files
TomCodedtargos
authored andcommitted
test: add module require tests for certain package.json errors
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 9749d48 commit b523f13

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
exports.ok = 'ok';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "missingmain",
3+
"main": "doesnotexist.js"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"main": "therain" "inspain"
3+
}

test/sequential/test-module-loading.js

+7
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ const d2 = require('../fixtures/b/d');
104104
assert.strictEqual(require('../fixtures/packages/index').ok, 'ok');
105105
assert.strictEqual(require('../fixtures/packages/main').ok, 'ok');
106106
assert.strictEqual(require('../fixtures/packages/main-index').ok, 'ok');
107+
assert.strictEqual(require('../fixtures/packages/missing-main').ok, 'ok');
108+
109+
assert.throws(
110+
function() { require('../fixtures/packages/unparseable'); },
111+
/^SyntaxError: Error parsing/
112+
);
107113

108114
{
109115
console.error('test cycles containing a .. path');
@@ -267,6 +273,7 @@ try {
267273
'fixtures/packages/index/index.js': {},
268274
'fixtures/packages/main/package-main-module.js': {},
269275
'fixtures/packages/main-index/package-main-module/index.js': {},
276+
'fixtures/packages/missing-main/index.js': {},
270277
'fixtures/cycles/root.js': {
271278
'fixtures/cycles/folder/foo.js': {}
272279
},

0 commit comments

Comments
 (0)