Skip to content

chore: convert lib/utils.js to ESM#6071

Open
arun-357 wants to merge 3 commits into
mochajs:mainfrom
arun-357:chore/convert-utils-to-esm
Open

chore: convert lib/utils.js to ESM#6071
arun-357 wants to merge 3 commits into
mochajs:mainfrom
arun-357:chore/convert-utils-to-esm

Conversation

@arun-357

Copy link
Copy Markdown

PR Checklist

Overview

Part of #5400. Renames lib/utils.jslib/utils.mjs and converts it to ESM named exports, updating every runtime call site and test in the same change. No behavior change.

  • Each exports.X = … becomes an inline export function/export const; internal exports.X self-references are now direct calls. No default/aggregate export (per AGENTS.md).
  • Call sites updated to match: CJS consumers require("./utils.mjs"), ESM named-import consumers from "./utils.mjs", and namespace consumers switched from import utils from to import * as utils from (a default import of a named-export module is undefined).
  • Tests: sinon cannot stub ES modules, so the sinon.stub(utils, …) calls were reworked — the unasserted isString/noop stubs were removed, and the isBrowser stubs were replaced with process.browser toggling (isBrowser() is Boolean(process.browser), so the same code path and assertions run). rewiremock keys/import paths were repointed to .mjs.

Verified: test-node suites, test-smoke, eslint, tsc, and a clean+build browser bundle all pass; lib/utils.js was not listed in package.json's browser map, so no config change was needed.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 14, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: arun-357 / name: arun-357 (cce77da)

Comment thread test/reporters/json.spec.js
Comment thread test/unit/mocha.spec.cjs
@mark-wiemer mark-wiemer added the status: waiting for author waiting on response from OP or other posters - more information needed label Jun 16, 2026
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 19.04762% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.43%. Comparing base (bab1d4e) to head (c4fd7a7).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
lib/utils.js 0.00% 34 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6071      +/-   ##
==========================================
- Coverage   82.25%   76.43%   -5.83%     
==========================================
  Files          61       61              
  Lines        4564     4561       -3     
  Branches      989      985       -4     
==========================================
- Hits         3754     3486     -268     
- Misses        810     1075     +265     

☔ View full report in Codecov by Harness.
📢 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.

@mark-wiemer mark-wiemer added status: needs review a maintainer should (re-)review this pull request and removed status: waiting for author waiting on response from OP or other posters - more information needed labels Jun 17, 2026
@arun-357

Copy link
Copy Markdown
Author

For code coverage, its not able to pick the natively loaded .mjs but tests still asserts the full utils as before.

@arun-357
arun-357 force-pushed the chore/convert-utils-to-esm branch from cce77da to 0206ea7 Compare June 22, 2026 20:34
@arun-357
arun-357 requested a review from mark-wiemer June 22, 2026 20:34
@arun-357

arun-357 commented Jun 22, 2026

Copy link
Copy Markdown
Author

Under the new type: module, plain .js is ESM — so do we want to keep it as .mjs or .js ? @mark-wiemer

@JoshuaKGoldberg

Copy link
Copy Markdown
Member

@arun-357 .js

@arun-357

Copy link
Copy Markdown
Author

@JoshuaKGoldberg No issue then, it is already a .js file in this PR.

@arun-357

arun-357 commented Jul 19, 2026

Copy link
Copy Markdown
Author

@mark-wiemer I fixed the conflicts.

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

Labels

status: needs review a maintainer should (re-)review this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🛠️ Repo: Convert lib/utils.js to ESM

3 participants