mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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: https://github.com/nodejs/node/issues/32013 PR-URL: https://github.com/nodejs/node/pull/32040 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
d5a06e73b6
commit
8ce6315e88
2
test/fixtures/require-empty-main/index.js
vendored
Normal file
2
test/fixtures/require-empty-main/index.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = 42;
|
1
test/fixtures/require-empty-main/package.json
vendored
Normal file
1
test/fixtures/require-empty-main/package.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"main":""}
|
25
test/parallel/test-require-empty-main.js
Normal file
25
test/parallel/test-require-empty-main.js
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user