Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
bnoordhuis committed Mar 2, 2020
commit 3704db3dcee711e129f171011da84abf689d87e0
2 changes: 2 additions & 0 deletions test/fixtures/require-empty-main/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
module.exports = 42;
1 change: 1 addition & 0 deletions test/fixtures/require-empty-main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"main":""}
25 changes: 25 additions & 0 deletions test/parallel/test-require-empty-main.js
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);
}