Skip to content

Commit 1987d59

Browse files
committed
Pass debug state through to step implementations
We don't actually use this yet, but we probably should in future, particularly to manage logging levels within step implementations.
1 parent 65c7759 commit 1987d59

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

src/rules/requests/request-rule.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface RequestRule extends Explainable {
2121
matches(request: OngoingRequest): MaybePromise<boolean>;
2222
handle(request: OngoingRequest, response: OngoingResponse, options: {
2323
record: boolean,
24+
debug: boolean,
2425
emitEventCallback?: (type: string, event: unknown) => void
2526
}): Promise<void>;
2627
isComplete(): boolean | null;
@@ -76,12 +77,14 @@ export class RequestRule implements RequestRule {
7677

7778
handle(req: OngoingRequest, res: OngoingResponse, options: {
7879
record?: boolean,
80+
debug: boolean,
7981
emitEventCallback?: (type: string, event: unknown) => void
8082
}): Promise<void> {
8183
let stepsPromise = (async () => {
8284
for (let step of this.steps) {
8385
const result = await step.handle(req, res, {
84-
emitEventCallback: options.emitEventCallback
86+
emitEventCallback: options.emitEventCallback,
87+
debug: options.debug
8588
});
8689

8790
if (!result || result.continue === false) break;

src/rules/requests/request-step-impls.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export interface RequestStepImpl extends RequestStepDefinition {
164164

165165
export interface RequestStepOptions {
166166
emitEventCallback?: (type: string, event: unknown) => void;
167+
debug: boolean;
167168
}
168169

169170
export class FixedResponseStepImpl extends FixedResponseStep {

src/rules/websockets/websocket-rule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface WebSocketRule extends Explainable {
3131
head: Buffer,
3232
options: {
3333
record: boolean,
34+
debug: boolean,
3435
emitEventCallback?: (type: string, event: unknown) => void
3536
}
3637
): Promise<void>;
@@ -91,6 +92,7 @@ export class WebSocketRule implements WebSocketRule {
9192
head: Buffer,
9293
options: {
9394
record: boolean,
95+
debug: boolean,
9496
emitEventCallback?: (type: string, event: unknown) => void
9597
}
9698
): Promise<void> {

src/server/mockttp-server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ export class MockttpServer extends AbstractMockttp implements Mockttp {
776776
if (this.debug) console.log(`Request matched rule: ${nextRule.explain()}`);
777777
await nextRule.handle(request, response, {
778778
record: this.recordTraffic,
779+
debug: this.debug,
779780
emitEventCallback: (this.eventEmitter.listenerCount('rule-event') !== 0)
780781
? (type, event) => this.announceRuleEventAsync(request.id, nextRule!.id, type, event)
781782
: undefined
@@ -849,6 +850,7 @@ export class MockttpServer extends AbstractMockttp implements Mockttp {
849850
if (this.debug) console.log(`Websocket matched rule: ${nextRule.explain()}`);
850851
await nextRule.handle(request, socket, head, {
851852
record: this.recordTraffic,
853+
debug: this.debug,
852854
emitEventCallback: (this.eventEmitter.listenerCount('rule-event') !== 0)
853855
? (type, event) => this.announceRuleEventAsync(request.id, nextRule!.id, type, event)
854856
: undefined

0 commit comments

Comments
 (0)