Skip to content

Commit 1470457

Browse files
bnoordhuiscodebytere
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 03aa2e1 commit 1470457

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
'use strict';
2+
module.exports=42;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"main":""}
Lines changed: 25 additions & 0 deletions
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+
constassert=require('assert');
12+
constpath=require('path');
13+
constfixtures=require('../common/fixtures');
14+
15+
constwhere=fixtures.path('require-empty-main');
16+
constexpected=path.join(where,'index.js');
17+
18+
test();
19+
setImmediate(test);
20+
21+
functiontest(){
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)