Skip to content

Commit 9390441

Browse files
committed
feat(cli): add ESM config loader
Since Node.js added support for loading ESM modules synchronously [1], the same mechanism can be reused, assuming an ESM module's file extension to be `.mjs`. Implements: #5049 [1] https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require
1 parent abf3dd9 commit 9390441

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/cli/config.js

Lines changed: 3 additions & 2 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',
@@ -71,9 +72,9 @@ exports.loadConfig = filepath => {
7172
try {
7273
if (ext === '.yml' || ext === '.yaml') {
7374
config = parsers.yaml(filepath);
74-
} else if (ext === '.js' || ext === '.cjs') {
75+
} else if (ext === '.js' || ext === '.cjs' || ext === '.mjs') {
7576
config = parsers.js(filepath);
76-
} else {
77+
} else {
7778
config = parsers.json(filepath);
7879
}
7980
} catch (err) {

0 commit comments

Comments
 (0)