Skip to content

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 >= 20.19.0

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.

* @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.

@thescientist13 thescientist13 changed the title feature/ESM configuration file feat: ESM configuration file Sep 24, 2025
@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author waiting on response from OP or other posters - more information needed label Sep 30, 2025
@JoshuaKGoldberg
Copy link
Member

👋 @thescientist13 just checking in, are you waiting on us for anything?

Now that #5358 is merged, this shouldn't have to worry about require(esm) not being supported. Though we are still seeing errors in other PRs (#5482, #5484, #5487) around that which we still need to debug. If you do see errors around CJS/ESM support you can ignore them for now.

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

Labels

status: waiting for author waiting on response from OP or other posters - more information needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Feature: ESM configuration file

2 participants