Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use index.js if package.json "main" is empty #32040

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}