Skip to content

🐛 Bug: .mocharc.js / .mocharc.mjs / ESM export default configs don't seem to work #5812

Description

@codegoblin

Bug Report Checklist

Expected

Given the explanation in the configuring mocha guide, I would expect a config file named .mocharc.js or .mocharc.mjs with the following contents to work:

console.log('mocha config');

export default {
  "extension": ["ts", "tsx"],
  "node-option": ["import=tsx"],
  "recursive": true,
  "reporter": "spec",
  "require": ["./test/setup.ts"],
  "spec": ["src/**/*.test.ts"],
  "timeout": 5000,
  "watch-files": ["src/**/*.ts", "test/**/*.ts"]
}

in package:

"type": "module",
...
"test": "cross-env NODE_ENV=test mocha",

Actual

When I run pnpm run test, the .mjs file is completely ignored, and the .js file is read (console output happens), but the export default { ... } seems to be ignored. Converting this config back to .mocharc.json works as expected.

Minimal, Complete and Verifiable Example

create a .mocharc.js config file with export default { ... } as the config interface and run the test suite. Config will be ignored.

Versions

version 11.7.5

Additional Info

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions