Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabueeee committed Jan 20, 2019
1 parent c002db1 commit be3c2ef
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ for (let matchedRequest of cssSpy.getMatchedRequests()) {
## API

### class: RequestInterceptor
The `RequestInterceptor` will match any intercepted request against the `matcher` function and notify all spies with a matching pattern and block requests matching any pattern in `urlsToBlock`.
The `RequestInterceptor` will call all spies, fakers and blocker to dertermine if an intercepted request matches. against the `matcher` function and notify all spies with a matching pattern and block requests matching any pattern in `urlsToBlock`.

#### RequestInterceptor constructor(matcher, logger?)
- `matcher`: <(url: string, pattern: string) => boolean>>
- `logger?`: <{log: (text: string) => void}>
- `matcher`: \<(url: string, pattern: string) =\> boolean\>\>
- `logger?`: \<{log: (text: string) =\> void}\>

The `matcher` will be called for every url, testing the url against patterns of any `RequestSpy` provided and also any url added to `urlsToBlock`.

Expand All @@ -118,17 +119,17 @@ The `logger` if provided will output any requested url with a 'loaded' or 'abort
Function to be registered with puppeteer's request event.

#### RequestInterceptor.addSpy(requestSpy)
- requestSpy: \<RequestSpy> spy to register
- requestSpy: \<IRequestSpy> spy to register

Register a spy with the `RequestInterceptor`.

#### RequestInterceptor.clearSpies()
Clears all registered spies.

#### RequestInterceptor.addFaker(requestFaker)
- responseFaker: \<ResponseFaker> faker to register
- responseFaker: \<IResponseFaker> faker to register

#### RequestInterceptor.clearFakers()
#### RequestInterceptor.clearFakers()
Clears all registered fakers.

#### RequestInterceptor.block(urlsToBlock)
Expand All @@ -142,7 +143,12 @@ Clears all registered fakers.
#### RequestInterceptor.clearUrlsToBlock()
Clears all registered patterns in `urlsToBlock`.

### class: RequestSpy
#### RequestInterceptor.setRequestBlocker(requestBlocker)
- requestBlocker \<IRequestBlocker\>

Allows you to replace the default RequestBlocker by your own implementation.

### class: RequestSpy implements IRequestSpy
`RequestSpy` is used to count and verify intercepted requests matching a specific pattern.
#### RequestSpy constructor(pattern)
- `pattern`: \<string|Array\<string>>
Expand All @@ -161,7 +167,9 @@ Clears all registered patterns in `urlsToBlock`.
#### RequestSpy.getMatchCount()
- returns: \<number> number of urls that matched the `pattern`

#### RequestSpy.isMatchingRequest(matcher: Matcher, request: Request)
#### RequestSpy.isMatchingRequest(request, matcher)
- request \<Request\> request object provided by puppeteer
- matcher \<(url: string, pattern: string) =\> boolean\>\> matching function passed to RequestInterceptor's constructor
- returns: \<boolean\> returns true if any pattern provided to the RequestSpy matches the request url

The `RequestInterceptor` calls this method to determine if an interceptedRequest matches the RequestSpy.
Expand All @@ -171,25 +179,45 @@ The `RequestInterceptor` calls this method to determine if an interceptedRequest

The `RequestInterceptor` calls this method when an interceptedRequest matches the pattern.

### class: RequestFaker
`RequestFaker` is used to provide a fake response when matched to a specific pattern.
### class: ResponseFaker implements IResponseFaker
`ResponseFaker` is used to provide a fake response when matched to a specific pattern.

#### RequestFaker constructor(pattern, responseFake)
#### ResponseFaker constructor(pattern, responseFake)
- `pattern`: \<string|Array<string>>
- `responseFake`: \<`Response`> for details refer to [puppeteer API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#requestrespondresponse)

#### RequestFaker.getPatterns()
#### ResponseFaker.getPatterns()
- returns: \<Array\<string\>\> return the `pattern` list of the faker

#### RequestFaker.getResponseFake()
#### ResponseFaker.getResponseFake()
- returns: \<Response\> return the fake response

The `RequestInterceptor` calls this method when an interceptedUrl matches the pattern.

#### RequestSpy.isMatchingRequest(matcher: Matcher, request: Request)
- returns: \<boolean\> returns true if any pattern provided to the RequestFaker matches the request url
#### ResponseFaker.isMatchingRequest(request, matcher)
- request \<Request\> request object provided by puppeteer
- matcher \<(url: string, pattern: string) =\> boolean\>\> matching function passed to RequestInterceptor's constructor
- returns: \<boolean\> returns true if any pattern provided to the ResponseFaker matches the request url

The `RequestInterceptor` calls this method to determine if an interceptedRequest matches.

### class: RequestBlocker implements IResponseBlocker
`RequestBlocker` is used to by the RequestInterceptor to match requests to block.

#### RequestBlocker.shouldBlockRequest(request, matcher)
- request \<Request\> request object provided by puppeteer
- matcher \<(url: string, pattern: string) =\> boolean\>\> matching function passed to RequestInterceptor's constructor

The `RequestInterceptor` calls this method to determine if an interceptedRequest matches.

#### RequestBlocker.addUrlsToBlock(urls)
- urls \<Array<string> | string\>

Adds new urls to the block list.

#### RequestBlocker.clearUrlsToBlock()

The `RequestInterceptor` calls this method to determine if an interceptedRequest matches the RequestFaker.
Removes all entries of the block list.

# Examples

Expand Down

0 comments on commit be3c2ef

Please sign in to comment.