Skip to content

build: use default node test runner with ecmascript modules#148

Merged
zimeg merged 7 commits intomainfrom
zimeg-build-actions-esm
Feb 6, 2026
Merged

build: use default node test runner with ecmascript modules#148
zimeg merged 7 commits intomainfrom
zimeg-build-actions-esm

Conversation

@zimeg
Copy link
Member

@zimeg zimeg commented Feb 4, 2026

Summary

This PR updates @actions/core to v3.0.0 and @actions/github to v9.0.0, which are now ESM-only packages. To support these dependencies, the codebase has been migrated to ES modules and tests now use the node:test built-in runner with esmock for module mocking.

Changes:

  • Add "type": "module" to package.json for ESM support
  • Convert all source files from CommonJS to ESM imports/exports
  • Convert all test files to use node:test instead of mocha/sinon/chai
  • Add esmock for ESM module mocking in tests
  • Remove unused mocha, sinon, and chai devDependencies
  • Remove obsolete .mocharc.json and test/.eslintrc.js configs

Closes #108
Closes #143
Closes #144

Requirements

zimeg and others added 3 commits February 4, 2026 11:56
This PR resolves #143 and #144 by updating the dependencies to their
ESM-only versions. Changes include:

- Add "type": "module" to package.json for ESM support
- Convert all source files from CommonJS to ESM imports/exports
- Convert all test files to use node:test instead of mocha/sinon/chai
- Remove unused mocha, sinon, and chai devDependencies
- Remove obsolete .mocharc.json and test/.eslintrc.js configs

The @actions/core and @actions/github packages are now ESM-only
as of versions 3.0.0 and 9.0.0 respectively.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Restore full test coverage for coverage.js and find-problematic-comments.js
using esmock to mock ESM module dependencies (node:child_process, node:fs,
@api/codecov).

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Use mocks.grep and mocks.coverage directly instead of separate exports.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg requested a review from a team as a code owner February 4, 2026 20:13
@zimeg zimeg self-assigned this Feb 4, 2026
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 99.11661% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.65%. Comparing base (43ab2c0) to head (33c0494).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
test/stubs/stubs.js 96.11% 4 Missing ⚠️
test/score_components/coverage-test.js 99.26% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
+ Coverage   94.57%   95.65%   +1.07%     
==========================================
  Files           6       12       +6     
  Lines         369     1610    +1241     
==========================================
+ Hits          349     1540    +1191     
- Misses         20       70      +50     

☔ 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.

@zimeg zimeg added dependencies Pull requests that update a dependency file javascript Pull requests that update Javascript code labels Feb 4, 2026
Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

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

LGTM 💯 left some non blocking comments

Comment on lines +151 to +159
mockCore.getInput.mock.mockImplementation((key) => {
const inputs = {
codecov_token: 'abcd1234',
codecov_max_attempts: '1',
codecov_retry_delay: '10',
codecov_treat_timeout_as_error: 'true',
};
return inputs[key] ?? '';
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever 💯

const cov = require('../../src/score_components/coverage');
import assert from 'node:assert';
import { beforeEach, describe, it, mock } from 'node:test';
import esmock from 'esmock';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I'm the biggest fan of this dependency 🤔 Could be nice to find a way to do this natively

Copy link
Member Author

@zimeg zimeg Feb 6, 2026

Choose a reason for hiding this comment

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

@WilliamBergamin I agree and plan to follow up with an investigation into this. At the moment these changes keep esmock to the following:

  • node:child_process
  • node:fs
  • @api/codecov

And we might adjust the src directories to inject these as dependencies for testing instead of direct imports? Will share findings!

Copy link

Choose a reason for hiding this comment

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

Sorry for the drive by comment, but node:test does have experimental module mocking. It might get the job done for you.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cjihrig Ahha no apologies! How else do we learn new things? It's so helpful to know but I'm wanting to merge this at this time!

I'll share changes soon 🔮

zimeg and others added 4 commits February 6, 2026 11:54
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg changed the title build: use default node test runner for unit test mocks build: use default node test runner with ecmascript modules Feb 6, 2026
@zimeg zimeg merged commit e469adc into main Feb 6, 2026
10 checks passed
@zimeg zimeg deleted the zimeg-build-actions-esm branch February 6, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants