-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
45a4fd0
commit bd09a75
Showing
3 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'use strict'; | ||
module.exports = 42; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"main":""} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
// A package.json with an empty "main" property should use index.js if present. | ||
// require.resolve() should resolve to index.js for the same reason. | ||
// | ||
// In fact, any "main" property that doesn't resolve to a file should result | ||
// in index.js being used, but that's already checked for by other tests. | ||
// This test only concerns itself with the empty string. | ||
|
||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const where = fixtures.path('require-empty-main'); | ||
const expected = path.join(where, 'index.js'); | ||
|
||
test(); | ||
setImmediate(test); | ||
|
||
function test() { | ||
assert.strictEqual(require.resolve(where), expected); | ||
assert.strictEqual(require(where), 42); | ||
assert.strictEqual(require.resolve(where), expected); | ||
} |