feat(testing): add Testing helpers (createBroker, EventCatcher, MockingCalls)#1346
Closed
aifunmobi wants to merge 6 commits into
Closed
feat(testing): add Testing helpers (createBroker, EventCatcher, MockingCalls)#1346aifunmobi wants to merge 6 commits into
aifunmobi wants to merge 6 commits into
Conversation
…ngCalls) Implements RFC moleculerjs#3 - Testing helpers for Moleculer. - createBroker(options, mockServices): Creates a real ServiceBroker with test middlewares pre-configured (logger disabled, test mode enabled) - EventCatcher middleware: Intercepts emit/broadcast/broadcastLocal, provides broker.test.eventEmitted(), waitForEvent(), etc. - MockingCalls middleware: Intercepts broker.call, supports mock responses with fluent API: mockAction("name").withParams({}).returnValue({}) - Exported via require("moleculer").Testing API surface (broker.test.*): Events: eventEmitted, eventEmittedTimes, eventEmittedWithParams, waitForEvent, getEvents, clearEvents Actions: mockAction, actionCalled, actionCalledTimes, actionCalledWithParams, getCalls, clearActions, clearMocks Utility: clearAll Closes moleculerjs/rfcs#3 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace optional catch binding (`catch {}`) with `catch (_err)` to
match the codebase convention and satisfy Codacy static analysis.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use parameterless catch blocks instead of catch (_err) to avoid unused variable warnings flagged by Codacy static analysis. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Assign middleware object to variable before returning to avoid PMD misinterpreting the object literal as a block statement. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Friendly ping — all checks are passing. Happy to address any feedback! |
Author
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.
Summary
Implements RFC #3 — Testing helpers for Moleculer.
createBroker(options, mockServices)— Creates a realServiceBrokerwith test middlewares pre-configured (logger disabled, test mode on)EventCatchermiddleware — Interceptsemit/broadcast/broadcastLocaland records all events for assertionMockingCallsmiddleware — Interceptsbroker.call, supports fluent mock API with param/meta matchingUsage
API (
broker.test.*)Events:
eventEmitted,eventEmittedTimes,eventEmittedWithParams,waitForEvent,getEvents,clearEventsActions:
mockAction(fluent:.withParams(),.withMeta(),.returnValue(),.rejectWith()),actionCalled,actionCalledTimes,actionCalledWithParams,getCalls,clearActions,clearMocksUtility:
clearAllTest plan
Design decisions
require("moleculer").Testingas specified in the RFCbroker.testnamespace avoids conflicts with existing broker APICloses moleculerjs/rfcs#3
🤖 Generated with Claude Code