mocha icon indicating copy to clipboard operation
mocha copied to clipboard

feat: ESM configuration file

Open thescientist13 opened this issue 5 months ago • 12 comments

PR Checklist

Overview

Introduces the ability to use ESM configuration files for Mocha, leveraging the require(ESM) capability of Node >= 20.19.0, and updated current and next docs.

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

TODO

  1. [x] Test Case
  2. [x] 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. 🫡

thescientist13 avatar Jul 01 '25 21:07 thescientist13

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: mark-wiemer / name: Mark Wiemer (80c9387e1be51357cb615e49d43b807c46c0e444, 0823a91553c39db013d3267cbc1d7e4382a0bb9e, 766d6ca17b2aca8b693efcd64406d54867d50949, ab07f1a07fd18bdb7f8fc90b6999a01d5846ad57)
  • :white_check_mark: login: thescientist13 / name: Owen Buckley (90f9daef230cffebbc12a63f8fbd8b39896b591c)

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

JoshuaKGoldberg avatar Oct 06 '25 13:10 JoshuaKGoldberg

hey @JoshuaKGoldberg , thanks for checking in!

Not waiting on anything per se, was just waiting to see what would happen with that other PR. I just rebased against main and pushed that up here with your feedback suggestion from earlier, so I can work on tests / docs if that's good with you.

thescientist13 avatar Oct 14 '25 13:10 thescientist13

Had some intermittent test failures locally, but none of them seemed related to the CLI changes here, so throwing this up to see what happens. 😅

thescientist13 avatar Oct 14 '25 14:10 thescientist13

Hi @thescientist13 , thanks for the PR :) I was sick for a while but have recovered, I've resolved merge conflicts and triggered the workflow to run. Please review the results and let me know if you need help addressing any potential new test failures (you can review #5361 for our known issues). I'll check back on this in a bit to do my first review, hopefully all tests pass today!

mark-wiemer avatar Nov 01 '25 16:11 mark-wiemer

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 93.68%. Comparing base (f75d150) to head (90f9dae).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5397      +/-   ##
==========================================
- Coverage   93.69%   93.68%   -0.02%     
==========================================
  Files          57       57              
  Lines        4396     4399       +3     
  Branches      849      851       +2     
==========================================
+ Hits         4119     4121       +2     
- Misses        277      278       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 01 '25 16:11 codecov[bot]

Thanks for checking in @mark-wiemer 👋

It looks like everything is passing, the only failures seem to be coming from running some of the codecov tasks?

==> Finishing downloading windows:latest
      Version: v11.2.4
 
gpg: directory '/c/Users/runneradmin/.gnupg' created
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
==> Verifying GPG signature integrity
 -> Downloading https://cli.codecov.io/latest/windows/codecov.exe.SHA256SUM
 -> Downloading https://cli.codecov.io/latest/windows/codecov.exe.SHA256SUM.sig
 
gpg: Signature made Thu Oct 23 15:06:32 2025 CUT
gpg:                using RSA key 27034E7FDB850E0BBC2C62FF806BB28AED779869
gpg: Can't check signature: No public key
==> Could not verify signature. Please contact Codecov if problem continues
    Exiting...
Error: Process completed with exit code 1.

There is still an open TODO item around documentation, so if you're initial review looks good, I can get that added too. Thinking something like this? https://mochajs.org/next/running/configuring/

  • JavaScript: Create a .mocharc.js (or .mocharc.cjs when using "type"="module" in your package.json) in your project's root directory, and export an object (module.exports = {/* ... */}) containing your configuration. For native ESM and using type="module" or using .mjs, use a default export (default export {/* ... */}).

(and should I do it for both old and new docs?)

thescientist13 avatar Nov 01 '25 16:11 thescientist13

We very recently switched to Codecov, I guess we'll have to work out this kink. But you're right, the tests did pass, so I'll review this one in a bit :)

mark-wiemer avatar Nov 01 '25 17:11 mark-wiemer

I'm not reviewing any PRs in detail right this moment, but I will be tomorrow. Turns out recovery from bronchitis has taken much longer than expected and I'm still not quite working 40 hours a week yet, so apologies for the delay. This is currently top of my list (but I have ~20 more PRs to check out tonight ;) )

mark-wiemer avatar Nov 22 '25 06:11 mark-wiemer

@thescientist13 an update to the docs would be much appreciated, and yes, please update both the old and new docs. Your current draft in your latest readme looks good :) You're welcome to add the changes to this PR

mark-wiemer avatar Nov 22 '25 14:11 mark-wiemer

Great, thanks @mark-wiemer . Will get that docs change going now. 👍

thescientist13 avatar Nov 22 '25 16:11 thescientist13

Docs changes pushed!

thescientist13 avatar Nov 22 '25 17:11 thescientist13