Skip to content

feature/ESM configuration file #5397

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thescientist13
Copy link

@thescientist13 thescientist13 commented Jul 1, 2025

PR Checklist

Overview

Introduces the ability to use ESM configuration files for Mocha, leveraging the require(ESM) capability of Node >= 22

See a demo repo with these patches here - https://github.com/thescientist13/mocha-esm-config

TODO

  1. Test Case
  2. Documentation

Per my understanding of support require(ESM) is so far only in >= 20.19.0, so not sure how this will fare with test cases running on Node 18, and or if this is something to just call out in the documentation? Not sure if will get backported to 18.x at this point as it is EOL now...

Either way, let me know your thoughts on the current implementation and the implications of Node support. Happy to add a test case / docs once I make sure this changeset is heading in the right direction. 🫡

Copy link

linux-foundation-easycla bot commented Jul 1, 2025

CLA Signed

  • ✅login: thescientist13 / (66732d2)

The committers listed above are authorized under a signed CLA.

@@ -64,13 +65,16 @@ const parsers = (exports.parsers = {
* @returns {Object} Parsed config object
*/
exports.loadConfig = filepath => {
const packageJson = require(path.resolve(utils.cwd(), 'package.json'));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's a better / more idiomatic way in Mocha to get the user's package.json file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally use something like package-up

But, determining whether the caller is CJS or ESM can be more tricky than that. My instinct is it'd be best to not add in specific logic for either. Using require(esm), we can do something simpler like packageJson.default ?? packageJson and call it a day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature: ESM configuration file
2 participants