Convert worker pool modules to ESM#6015
Open
macayu17 wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR migrates Mocha’s parallel-mode worker/reporting internals toward ESM (.mjs) and improves unit-testability by extracting injectable “core” factories, replacing rewiremock usage in tests.
Changes:
- Added ESM worker entrypoint (
worker.mjs) and extracted worker runtime logic intoworker-core.mjswith dependency injection. - Added ESM implementations/factories for
buffered-worker-poolandparallel-bufferedreporter; updated unit tests to use these factories directly. - Updated parallel runner/test wiring and
package.jsonbrowser exclusions to reference new.mjsentrypoints.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/node-unit/worker.spec.js | Switches worker tests from rewiremock to startWorker() with injected deps. |
| test/node-unit/reporters/parallel-buffered.spec.js | Switches reporter tests from rewiremock to createParallelBufferedClass() and real serializer types. |
| test/node-unit/parallel-buffered-runner.spec.js | Removes rewiremock, stubs BufferedWorkerPool.create, adjusts fatal error expectation. |
| test/node-unit/mocha.spec.js | Updates stubbed runner path to .mjs + named export. |
| test/node-unit/buffered-worker-pool.spec.js | Uses createBufferedWorkerPoolClass() instead of rewiremock. |
| package.json | Updates browser field exclusions to .mjs parallel/worker paths. |
| lib/nodejs/worker.mjs | New ESM worker entrypoint delegating to startWorker(). |
| lib/nodejs/worker.js | Removes old CJS worker implementation. |
| lib/nodejs/worker-core.mjs | New extracted worker runtime with injectable dependencies + startWorker(). |
| lib/nodejs/reporters/parallel-buffered.mjs | New ESM reporter + factory to inject Base/serializer types. |
| lib/nodejs/reporters/parallel-buffered.js | Removes old CJS reporter implementation. |
| lib/nodejs/parallel-buffered-runner.js | Converts runner implementation to ESM-style imports/exports (but retains .js filename). |
| lib/nodejs/buffered-worker-pool.mjs | New ESM workerpool wrapper + injectable factory. |
| lib/nodejs/buffered-worker-pool.js | Removes old CJS workerpool wrapper. |
| lib/mocha.js | Updates parallel runner resolution to point at .mjs named export. |
| // swap Runner class | ||
| this._runnerClass = parallel | ||
| ? require("./nodejs/parallel-buffered-runner") | ||
| ? require("./nodejs/parallel-buffered-runner.mjs").ParallelBufferedRunner |
| /** | ||
| * A mapping of Mocha `Options` objects to serialized values. | ||
| * | ||
| * This is helpful because we tend to same the same options over and over |
Comment on lines
+68
to
+72
| * Runs a single test file in a worker thread. | ||
| * @param {string} filepath - Filepath of test file | ||
| * @param {string} [serializedOptions] - **Serialized** options. This string will be eval'd! | ||
| * @see https://npm.im/serialize-javascript | ||
| * @returns {Promise<{failures: number, events: BufferedEvent[]}>} - Test |
| if (!filepath) { | ||
| throw createInvalidArgumentTypeError( | ||
| 'Expected a non-empty "filepath" argument', | ||
| "file", |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6015 +/- ##
==========================================
- Coverage 80.89% 80.16% -0.74%
==========================================
Files 64 65 +1
Lines 4602 4624 +22
Branches 976 1016 +40
==========================================
- Hits 3723 3707 -16
- Misses 879 916 +37
- Partials 0 1 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
lib/nodejs/worker pool files to ESM #5969status: accepting prsOverview
Converts the
lib/nodejsworker pool modules from CommonJS to ESM.This updates the worker pool, parallel runner, worker entrypoint, and buffered worker reporter to use
.mjsfiles with named runtime exports. The worker setup now lives behind a small injectable helper so the unit tests no longer need to mock CommonJS loading for these modules.Validated with the relevant node, integration, lint, typecheck, build, and browser test scripts.