-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed not working on all lang levels; improved typings documentation …
…and examplex
- Loading branch information
Showing
7 changed files
with
59 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
import {RespondOptions} from 'puppeteer'; | ||
import {RequestInspector} from './RequestInspector'; | ||
|
||
export class ResponseFaker extends RequestInspector { | ||
export class ResponseFaker { | ||
|
||
private responseFake: RespondOptions; | ||
private patterns: Array<string> = []; | ||
|
||
public constructor(patterns: Array<string> | string, responseFake: RespondOptions) { | ||
super(patterns); | ||
if (typeof patterns !== 'string' && patterns.constructor !== Array) { | ||
throw new Error('invalid pattern, pattern must be of type string or string[].'); | ||
} | ||
|
||
if (typeof patterns === 'string') { | ||
patterns = [patterns]; | ||
} | ||
|
||
this.patterns = patterns; | ||
this.responseFake = responseFake; | ||
} | ||
|
||
public getResponseFake(): RespondOptions { | ||
return this.responseFake; | ||
} | ||
|
||
public getPatterns(): Array<string> { | ||
return this.patterns; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,43 @@ | ||
import {Request, RespondOptions} from 'puppeteer'; | ||
import {Logger} from './common/Logger'; | ||
import { Request } from 'puppeteer'; | ||
import { Logger } from './common/Logger'; | ||
|
||
export declare abstract class RequestInspector { | ||
private patterns; | ||
|
||
constructor(patterns: Array<string> | string); | ||
|
||
getPatterns(): Array<string>; | ||
} | ||
|
||
/** | ||
* @description 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. | ||
**/ | ||
export declare class RequestInterceptor { | ||
private spies; | ||
private requestSpies; | ||
private responseFakers; | ||
private urlsToBlock; | ||
private matcher; | ||
private logger; | ||
|
||
constructor(matcher: (testString: string, pattern: string) => boolean, logger?: Logger); | ||
|
||
intercept(interceptedUrl: Request): void; | ||
|
||
intercept(interceptedUrl: Request): Promise<void>; | ||
addSpy(requestSpy: RequestSpy): void; | ||
|
||
addFaker(responseFaker: ResponseFaker): void; | ||
block(urls: Array<string> | string): void; | ||
|
||
clearSpies(): void; | ||
|
||
clearFakers(): void; | ||
clearUrlsToBlock(): void; | ||
|
||
setUrlsToBlock(urlsToBlock: Array<string>): void; | ||
|
||
private blockUrl(interceptedUrl); | ||
|
||
private acceptUrl(interceptedUrl); | ||
private blockUrl(interceptedUrl, url); | ||
private acceptUrl(interceptedUrl, url); | ||
} | ||
|
||
/** | ||
* @description RequestSpy is used to count and verify intercepted requests matching a specific pattern. | ||
**/ | ||
export declare class RequestSpy extends RequestInspector { | ||
export declare class RequestSpy { | ||
private hasMatchingUrl; | ||
private matchedUrls; | ||
private matchCount; | ||
|
||
private patterns; | ||
constructor(patterns: Array<string> | string); | ||
|
||
getPatterns(): Array<string>; | ||
hasMatch(): boolean; | ||
|
||
getMatchedUrls(): Array<string>; | ||
|
||
getMatchCount(): number; | ||
|
||
addMatchedUrl(interceptedRequest: string): void; | ||
addMatchedUrl(matchedUrl: string): void; | ||
} | ||
|
||
/** | ||
* @description RequestFaker is used to provide a fake response when matched to a specific pattern. | ||
**/ | ||
export declare class ResponseFaker extends RequestInspector { | ||
import { RespondOptions } from 'puppeteer'; | ||
export declare class ResponseFaker { | ||
private responseFake; | ||
|
||
private patterns; | ||
constructor(patterns: Array<string> | string, responseFake: RespondOptions); | ||
|
||
getResponseFake(): RespondOptions; | ||
getPatterns(): Array<string>; | ||
} |