Skip to content

refactor!: remove unused legacy errors.js functions - #5835

Merged
mark-wiemer merged 4 commits into
mainfrom
voxpelli/remove-emitwarning-polyfill
Apr 29, 2026
Merged

mark-wiemer merged 4 commits into
mainfrom
voxpelli/remove-emitwarning-polyfill

Conversation

@voxpelli

@voxpelli voxpelli commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

Removes these from errors.js:

  • warn() is no longer used anywhere and not publicly exported
  • createInvalidPluginError() is no longer used anywhere, isn't publicly exported had to be explicitly imported from the specific file, has been deprecated since implementation of global setup/teardown; closes #4308 #4360, for 6 years now and has no public usage across GitHub
  • deprecate() was only used by createInvalidPluginError() and not publicly exported
  • emitWarning() was only used by warn() and deprecate() and contained an unnecessary polyfill for process.emitWarning, a function that has existed since Node 6.0.0 with us now requiring at least Node 20.19.0 - and it wasn't publicly exported.

This change simplifies the codebase by eliminating unused functions and their tests as well as their redundant polyfills.

PR Checklist

Applicable issues

@voxpelli voxpelli self-assigned this Mar 31, 2026
@voxpelli
voxpelli requested review from a team and Copilot March 31, 2026 13:09
@voxpelli voxpelli added this to the v12.0.0 milestone Mar 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes a legacy process.emitWarning polyfill in lib/errors.js, intending to rely solely on the native Node.js implementation now that Mocha’s minimum supported Node version is ^20.19.0 || >=22.12.0.

Changes:

  • Remove the emitWarning polyfill wrapper from lib/errors.js and call process.emitWarning directly from deprecate() and warn().
  • Simplify unit tests by always stubbing process.emitWarning in test/unit/errors.spec.js.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/errors.js Removes the emitWarning wrapper and calls process.emitWarning directly for warnings/deprecations.
test/unit/errors.spec.js Simplifies setup/teardown around process.emitWarning stubbing in deprecate/warn tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/errors.js Resolved
Comment thread test/unit/errors.spec.js Resolved
Comment thread test/unit/errors.spec.js Resolved
@codecov

codecov Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.56%. Comparing base (1b3d604) to head (d42cb24).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5835   +/-   ##
=======================================
  Coverage   88.55%   88.56%           
=======================================
  Files          65       65           
  Lines        4659     4643   -16     
  Branches      978      974    -4     
=======================================
- Hits         4126     4112   -14     
+ Misses        533      531    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@voxpelli
voxpelli force-pushed the voxpelli/remove-emitwarning-polyfill branch 3 times, most recently from f05cc93 to 0f77459 Compare March 31, 2026 13:50
@voxpelli voxpelli changed the title refactor: remove legacy process.emitWarning polyfill refactor: remove unused legacy errors.js functions Mar 31, 2026
@voxpelli
voxpelli requested a review from Copilot March 31, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

test/unit/suite.spec.js:533

  • The removed errors.deprecate stub means the errors import at the top of this file is now unused (only appears in the require). With ESLint js/recommended, this will trigger a no-unused-vars failure; please remove the unused errors import.
    describe("constructor", function () {
      /* eslint no-new: off */
      it("should throw an error if the title isn't a string", function () {
        expect(function () {
          new Suite(undefined, "root");

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/unit/mocha.spec.js Resolved
Comment thread lib/errors.js Resolved
- `warn()` is no longer used anywhere
- `createInvalidPluginError()` is no longer used anywhere and has been deprecated since #4360, for 6 years now
- `deprecate()` was only used by `createInvalidPluginError()`
- `emitWarning()` was only used by `warn()` and `deprecate()` and contained an unnecessary polyfill for `process.emitWarning`, a function that has existed since Node 6.0.0 with us now requiring at least Node 20.19.0

Ref: #5357 (v12 Release Plan)
@voxpelli
voxpelli force-pushed the voxpelli/remove-emitwarning-polyfill branch from 0f77459 to 29de573 Compare March 31, 2026 14:02
@voxpelli voxpelli added status: needs review a maintainer should (re-)review this pull request type: cleanup a refactor labels Mar 31, 2026

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, with the caveat that removing createInvalidPluginError is actually a breaking change and this PR should be rephrased as such.

Can I suggest manually writing the PR description?

Comment thread lib/errors.js Resolved
@voxpelli

voxpelli commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

@JoshuaKGoldberg I did manually write the majority of the final PR description.

As far as I can see the createInvalidPluginError is not a public API? So it shouldn't be a breaking change to remove it?

@JoshuaKGoldberg

Copy link
Copy Markdown
Member

As far as I can see the createInvalidPluginError is not a public API? So it shouldn't be a breaking change to remove it?

#5835 (comment)

@voxpelli voxpelli changed the title refactor: remove unused legacy errors.js functions refactor!: remove unused legacy errors.js functions Apr 2, 2026
@mark-wiemer mark-wiemer added the semver-major implementation requires increase of "major" version number; "breaking changes" label Apr 3, 2026
@mark-wiemer mark-wiemer modified the milestones: v12.0.0, v13.0.0 Apr 4, 2026
@mark-wiemer mark-wiemer added semver-major implementation requires increase of "major" version number; "breaking changes" and removed semver-major implementation requires increase of "major" version number; "breaking changes" labels Apr 20, 2026
@mark-wiemer

Copy link
Copy Markdown
Member

@JoshuaKGoldberg I'm good to merge this into v12 if you are now that we've updated #5357. One of the callouts is explicitly "removing long-deprecated options" :)

@mark-wiemer

Copy link
Copy Markdown
Member

I will fix the formatting issue separately

@mark-wiemer

Copy link
Copy Markdown
Member

@JoshuaKGoldberg you OK to merge this into v12?

@mark-wiemer mark-wiemer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the record I did review the actual code :)

@JoshuaKGoldberg

Copy link
Copy Markdown
Member

At this point I don't feel strongly. If you guys are ok with breaking the letter of the law to go with this interpretation of the spirit, I won't stand in the way. ✅

@mark-wiemer
mark-wiemer merged commit 4116368 into main Apr 29, 2026
82 checks passed
@mark-wiemer
mark-wiemer deleted the voxpelli/remove-emitwarning-polyfill branch April 29, 2026 01:26
@mark-wiemer

Copy link
Copy Markdown
Member

#5357 says "Mocha 12 will be used to ... Remove long-deprecated options and any other known dead code", I think this counts :)

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

Labels

semver-major implementation requires increase of "major" version number; "breaking changes" status: needs review a maintainer should (re-)review this pull request type: cleanup a refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants