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

Fixes #4665. make "-r <dir>" work with new import-first loading #4668

Merged
merged 1 commit into from
Jun 28, 2021
Merged
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
3 changes: 2 additions & 1 deletion lib/esm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ exports.requireOrImport = hasStableEsmImplementation
} catch (err) {
if (
err.code === 'ERR_MODULE_NOT_FOUND' ||
err.code === 'ERR_UNKNOWN_FILE_EXTENSION'
err.code === 'ERR_UNKNOWN_FILE_EXTENSION' ||
err.code === 'ERR_UNSUPPORTED_DIR_IMPORT'
) {
return require(file);
} else {
Expand Down
16 changes: 16 additions & 0 deletions test/integration/esm.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
var path = require('path');
var helpers = require('./helpers');
var run = helpers.runMochaJSON;
var runMochaAsync = helpers.runMochaAsync;
Expand Down Expand Up @@ -65,4 +66,19 @@ describe('esm', function() {
done();
});
});

it('should enable requiring/loading a cjs module with "dir" as filename', async function() {
var fixture = 'esm/test-that-uses-dir-cjs-require.fixture.js';
const result = await runMochaAsync(
fixture,
[
...args,
'--require',
path.resolve(__dirname, './fixtures/esm/dir-cjs-require')
],
{stdio: 'pipe'}
);

expect(result, 'to have passed test count', 1);
});
});
1 change: 1 addition & 0 deletions test/integration/fixtures/esm/dir-cjs-require/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global.testPassesIfThisVariableIsDefined = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// See https://github.com/mochajs/mocha/issues/4665 for an explanation of this test
juergba marked this conversation as resolved.
Show resolved Hide resolved
it('should require a dir import', () => {
expect(global.testPassesIfThisVariableIsDefined, 'to be', true)
})