Skip to content

Commit

Permalink
FormidableLabs#64 More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwsperber committed Mar 29, 2020
1 parent 17d6617 commit 437e11f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,25 @@ export interface IInterceptEvent {
requestSerializer: RequestSerializer;
}

/**
* Configure intercept
*/
export interface IInterceptOptions {
/**
* Do not intercept outbound requests on these ports.
*
* By default MITM will intercept activity on any socket, HTTP or otherwise.
* If you need to ignore a port (eg for a database connection), provide that port number here.
*
* In practice YesNo normally runs after long running connections have been established,
* so this won't be a problem.
*/
ignorePorts?: number[];
}

/**
* Emit whenever we have proxied a request to its original destination
*/
export interface IProxiedEvent {
requestSerializer: RequestSerializer;
responseSerializer: ResponseSerializer;
Expand Down
11 changes: 11 additions & 0 deletions src/mock-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { RecordMode as Mode } from './recording';

const debug: IDebugger = require('debug')('yesno:mock-response');

/**
* Encapsulates logic for sending a response for an intercepted HTTP request
*/
export default class MockResponse {
private event: IInterceptEvent;
private ctx: Context;
Expand All @@ -25,6 +28,14 @@ export default class MockResponse {
this.event = event;
}

/**
* Send a respond for our wrapped intercept event if able.
*
* Give precedence to matching responses in shared context (from `yesno.matching().respond()`).
* Else, if we're in mock mode, lookup the mock response.
*
* @returns The received request & sent response. Returns `undefined` if unable to respond
*/
public async send(): Promise<ISeralizedRequestResponse | undefined> {
const {
interceptedRequest,
Expand Down
7 changes: 7 additions & 0 deletions src/yesno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ export interface IRecordableTest {
dir: string;
}

/**
* Options to configure intercept of HTTP requests
*/
export interface IYesNoInterceptingOptions extends IInterceptOptions {
/**
* Comparator function used to determine whether an intercepted request
* matches a loaded mock.
*/
comparatorFn?: ComparatorFn;
}

Expand Down

0 comments on commit 437e11f

Please sign in to comment.