-
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.
Merge pull request #10 from Tabueeee/v-1.3.0
v-1.3.0: Interfaces and isMatchingRequest for more flexibility
- Loading branch information
Showing
55 changed files
with
737 additions
and
166 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
This Project uses Semantic Versioning. More information can be found [here](https://semver.org/). | ||
|
||
The branch and tag names also follow the following convention: | ||
- branches: ```v-x.y.z``` | ||
- tags: ```vx.y.z``` | ||
|
||
You only need to follow this convention when creating a Pull Request for a full npm release. | ||
|
||
Please make sure your branch passes the build process by running ```npm test```. | ||
You can check the code coverage by generating a html report using ```npm run test-coverage```. | ||
|
||
The tslint setting may seem harsh but they are usually useful to determine problems. | ||
Try to fix as much as possible but I am not contempt on keeping every rule. | ||
Some are a matter of choice after all. | ||
|
||
If you want to ensure a proper release, bump the version in the package.json and run ```npm run release-dry```. | ||
This will run all required steps for a successful release like ts-lint, build, test, generating types | ||
and creates a preview of the final package pushed to npm. |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Request} from 'puppeteer'; | ||
import {RespondOptions} from 'puppeteer'; | ||
import {IResponseFaker, RequestMatcher} from 'puppeteer-request-spy'; | ||
|
||
export class CustomFaker implements IResponseFaker { | ||
|
||
private patterns: Array<string> = []; | ||
private fakesMap = { | ||
'GET': 'some text', | ||
'POST': 'Not Found!' | ||
}; | ||
|
||
public constructor(patterns: Array<string>) { | ||
this.patterns = patterns; | ||
} | ||
|
||
public getResponseFake(request: Request): RespondOptions { | ||
return { | ||
status: 200, | ||
contentType: 'text/plain', | ||
body: this.fakesMap[request.method()] | ||
}; | ||
} | ||
|
||
public isMatchingRequest(request: Request, matcher: RequestMatcher): boolean { | ||
for (let pattern of this.patterns) { | ||
if(matcher(request.url(), pattern)){ | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {IRequestSpy, RequestMatcher} from 'puppeteer-request-spy'; | ||
import {Request, Response} from 'puppeteer'; | ||
import * as assert from "assert"; | ||
|
||
|
||
export class CustomSpy implements IRequestSpy { | ||
private matches: Array<Request> = []; | ||
|
||
public isMatchingRequest(request: Request, matcher: RequestMatcher): boolean { | ||
|
||
return matcher(request.url(), '**/*'); | ||
} | ||
|
||
public addMatch(matchedRequest: Request): void { | ||
|
||
this.matches.push(matchedRequest); | ||
} | ||
|
||
public assertRequestsOk() { | ||
for (let match of this.matches) { | ||
let response: Response | null = match.response(); | ||
if (response !== null) { | ||
assert.ok(response.ok()); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {Request} from 'puppeteer'; | ||
import {UrlAccessor} from './common/urlAccessor/UrlAccessor'; | ||
import {UrlAccessorResolver} from './common/urlAccessor/UrlAccessorResolver'; | ||
import {IRequestBlocker} from './interface/IRequestBlocker'; | ||
import {RequestMatcher} from './interface/RequestMatcher'; | ||
|
||
export class RequestBlocker implements IRequestBlocker { | ||
|
||
private urlsToBlock: Array<string> = []; | ||
|
||
public shouldBlockRequest(request: Request, matcher: RequestMatcher): boolean { | ||
let urlAccessor: UrlAccessor = UrlAccessorResolver.getUrlAccessor(request); | ||
|
||
for (let urlToBlock of this.urlsToBlock) { | ||
if (matcher(urlAccessor.getUrlFromRequest(request), urlToBlock)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public addUrlsToBlock(urls: Array<string> | string): void { | ||
this.urlsToBlock = this.urlsToBlock.concat(urls); | ||
} | ||
|
||
public clearUrlsToBlock(): void { | ||
this.urlsToBlock = []; | ||
} | ||
} |
Oops, something went wrong.