Skip to content

Commit 862cd2b

Browse files
bnoordhuisMylesBorins
authored andcommitted
test: use index.js if package.json "main" is empty
Verify that the module loader uses index.js when the "main" property of package.json is the empty string. Refs: #32013 PR-URL: #32040 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 3d64c9e commit 862cd2b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
'use strict';
2+
module.exports = 42;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"main":""}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
require('../common');
3+
4+
// A package.json with an empty "main" property should use index.js if present.
5+
// require.resolve() should resolve to index.js for the same reason.
6+
//
7+
// In fact, any "main" property that doesn't resolve to a file should result
8+
// in index.js being used, but that's already checked for by other tests.
9+
// This test only concerns itself with the empty string.
10+
11+
const assert = require('assert');
12+
const path = require('path');
13+
const fixtures = require('../common/fixtures');
14+
15+
const where = fixtures.path('require-empty-main');
16+
const expected = path.join(where, 'index.js');
17+
18+
test();
19+
setImmediate(test);
20+
21+
function test() {
22+
assert.strictEqual(require.resolve(where), expected);
23+
assert.strictEqual(require(where), 42);
24+
assert.strictEqual(require.resolve(where), expected);
25+
}

0 commit comments

Comments
 (0)