-
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.
integrated changes from feature/allow_mocking_by_method and updated t…
…ests, typings, documentation and naming
- Loading branch information
Showing
52 changed files
with
476 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,3 +126,4 @@ build/**/*.js.map | |
custom-typings/ | ||
.travis.yml | ||
.coveralls.yml | ||
CONTRIBUTING.md |
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: ```v.x.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export interface Logger { | ||
export interface ILogger { | ||
log(message: string): void; | ||
} |
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,7 @@ | ||
import {IRequestBlocker} from '../../interface/IRequestBlocker'; | ||
|
||
export function instanceOfRequestBlocker(object: object): object is IRequestBlocker { | ||
return typeof (<IRequestBlocker>object).shouldBlockRequest === 'function' | ||
&& typeof (<IRequestBlocker>object).clearUrlsToBlock === 'function' | ||
&& typeof (<IRequestBlocker>object).addUrlsToBlock === 'function'; | ||
} |
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,6 @@ | ||
import {IResponseFaker} from '../../'; | ||
|
||
export function instanceOfRequestFaker(object: object): object is IResponseFaker { | ||
return typeof (<IResponseFaker>object).getResponseFake === 'function' | ||
&& typeof (<IResponseFaker>object).isMatchingRequest === 'function'; | ||
} |
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,6 @@ | ||
import {IRequestSpy} from '../../'; | ||
|
||
export function instanceOfRequestSpy(object: object): object is IRequestSpy { | ||
return typeof (<IRequestSpy>object).addMatch === 'function' | ||
&& typeof (<IRequestSpy>object).isMatchingRequest === 'function'; | ||
} |
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
Oops, something went wrong.