Skip to content

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

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

chore: convert lib/utils.js to ESM#6071
arun-357 wants to merge 1 commit 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.mjs
Comment thread test/unit/mocha.spec.js
Suite = sinon.stub(Mocha, "Suite").returns(suite);
Suite.constants = {};

sinon.stub(utils, "isString");

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.

Can you explain how these tests aren't false negatives with this change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nothing ever asserted on these stubs, so they weren't testing anything

@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 17.07317% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.33%. Comparing base (fb1998a) to head (cce77da).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
lib/utils.mjs 0.00% 34 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6071      +/-   ##
==========================================
- Coverage   78.12%   72.33%   -5.80%     
==========================================
  Files          63       63              
  Lines        4590     4587       -3     
  Branches      977      981       +4     
==========================================
- Hits         3586     3318     -268     
- Misses       1004     1269     +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.

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.

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

2 participants