feat: add testing helpers (createBroker, EventCatcher, MockingCalls)#1358
Closed
steven-ge007 wants to merge 1 commit into
Closed
feat: add testing helpers (createBroker, EventCatcher, MockingCalls)#1358steven-ge007 wants to merge 1 commit into
steven-ge007 wants to merge 1 commit into
Conversation
Implements RFC moleculerjs#3 - Testing helpers for Moleculer microservices. - EventCatcher middleware: captures emit/broadcast/broadcastLocal events - MockingCalls middleware: intercepts broker.call for mocking - createBroker factory: pre-configured test broker with both middlewares - Full TypeScript definitions - 22 unit tests Closes moleculerjs/rfcs#3 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Closing this PR. There are multiple duplicate PRs implementing the same RFC #3, and we'll be handling the testing helpers implementation internally as part of the v0.15 release. Thank you for your interest in contributing to Moleculer. |
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.
Description
Implements the testing helpers proposed in RFC #3. This adds three new tools for writing tests in Moleculer microservices:
createBroker(opts, mockServices)Factory function that creates a ServiceBroker pre-configured for testing with logging disabled,
test: trueflag, and both testing middlewares auto-registered.EventCatcher middleware
Captures all emit, broadcast, and broadcastLocal events for test assertions:
MockingCalls middleware
Intercepts broker.call for mocking and call tracking:
Files changed
src/middlewares/testing.js- EventCatcher and MockingCalls middlewaressrc/middlewares/index.js- Export Testing namespacesrc/testing.js- createBroker factory functionsrc/testing.d.ts- TypeScript type definitionsindex.js/index.mjs- Export Testing moduletest/unit/middlewares/testing.spec.js- 22 test casesTest Plan
All 2356 tests pass (137 suites), 22 new tests for the testing module.
Closes moleculerjs/rfcs#3