mochajs / mocha

☕️ simple, flexible, fun javascript test framework for node.js & the browser
https://mochajs.org
MIT License
22.53k stars 3.01k forks source link

🐛 Bug: remove util.inherits / convert to classes #5025

Open jimmywarting opened 10 months ago

jimmywarting commented 10 months ago

Is your feature request related to a problem or a nice-to-have?? Please describe. It would be nice to get rid of some NodeJS specific things that makes it better suited for browsers. one such thing could be the option to remove util.inherits and replacing it with classes that can extends things. resulting in fewer dependencies and smaller code bundle that won't require the browserified version of util that has an additional of 20 modules and 12 kb

NodeJS docs have marked it as legacy and has this to say about util.inherits

Usage of util.inherits() is discouraged. Please use the ES6 class and extends keywords to get language level inheritance support

Describe the solution you'd like Change prototype based classes into es-classes

voxpelli commented 1 month ago

Fully agree!

Some classes that needs to be converted:

If we can find a linting rule that enforces / helps with this, then we should

JoshuaKGoldberg commented 1 month ago

Bad news: I think this would technically be a breaking change. Out of the three PRs that split it up:

...indicating that the runtime differences noted in https://nodejs.org/api/util.html#utilinheritsconstructor-superconstructor do impact usage of these class(-like)s.

These are all part of the public Mocha API:

As much as we want to clean up this old code, we'll have to wait for the next major version of Mocha. 😞

voxpelli commented 1 month ago

I think we should get planning for a new major version fairly soon, as it eg is needed to update some outdated dependencies as well

We can keep a 10.x branch around for bug fixes and have main be for the next major?

JoshuaKGoldberg commented 1 month ago

get planning for a new major version fairly soon

Agreed, the more I dig into the legacy dependencies the more breaking changes I find...

For visibility: we'll talk about this in our next maintainer meeting to see what strategy we go with. 👍