Skip to content

Commit 66732d2

Browse files
support loading ESM configuration files
1 parent c12d85d commit 66732d2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/cli/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const utils = require('../utils');
2424
exports.CONFIG_FILES = [
2525
'.mocharc.cjs',
2626
'.mocharc.js',
27+
'.mocharc.mjs',
2728
'.mocharc.yaml',
2829
'.mocharc.yml',
2930
'.mocharc.jsonc',
@@ -64,13 +65,16 @@ const parsers = (exports.parsers = {
6465
* @returns {Object} Parsed config object
6566
*/
6667
exports.loadConfig = filepath => {
68+
const packageJson = require(path.resolve(utils.cwd(), 'package.json'));
6769
let config = {};
6870
debug('loadConfig: trying to parse config at %s', filepath);
6971

7072
const ext = path.extname(filepath);
7173
try {
7274
if (ext === '.yml' || ext === '.yaml') {
7375
config = parsers.yaml(filepath);
76+
} else if ((ext === '.js' && packageJson.type === "module") || ext === '.mjs') {
77+
config = parsers.js(filepath).default;
7478
} else if (ext === '.js' || ext === '.cjs') {
7579
config = parsers.js(filepath);
7680
} else {

0 commit comments

Comments
 (0)