chore: hide request interception for 1.13 (#7425)

This commit is contained in:
Max Schmitt 2021-07-01 18:33:47 +02:00 committed by GitHub
parent 9c3ae38914
commit 027fc4c0b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 59 deletions

View file

@ -220,31 +220,6 @@ Optional response body as raw bytes.
File path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it
is resolved relative to the current working directory.
## async method: Route.intercept
- returns: <[Response]>
Continues route's request with optional overrides and intercepts response.
### option: Route.intercept.url
- `url` <[string]>
If set changes the request URL. New URL must have same protocol as original one.
### option: Route.intercept.method
- `method` <[string]>
If set changes the request method (e.g. GET or POST)
### option: Route.intercept.postData
- `postData` <[string]|[Buffer]>
If set changes the post data of request
### option: Route.intercept.headers
- `headers` <[Object]<[string], [string]>>
If set changes the request HTTP headers. Header values will be converted to a string.
## method: Route.request
- returns: <[Request]>

View file

@ -302,7 +302,7 @@ export class Route extends ChannelOwner<channels.RouteChannel, channels.RouteIni
});
}
async intercept(options: { url?: string, method?: string, headers?: Headers, postData?: string | Buffer, interceptResponse?: boolean } = {}): Promise<api.Response> {
async _intercept(options: { url?: string, method?: string, headers?: Headers, postData?: string | Buffer, interceptResponse?: boolean } = {}): Promise<api.Response> {
return await this._continue(options, true);
}

View file

@ -22,7 +22,8 @@ import { test as it, expect } from './pageTest';
it('should fulfill intercepted response', async ({page, server, browserName}) => {
it.fixme(browserName === 'firefox');
await page.route('**/*', async route => {
await route.intercept({});
// @ts-expect-error
await route._intercept({});
await route.fulfill({
status: 201,
headers: {
@ -48,7 +49,8 @@ it('should throw on continue after intercept', async ({page, server, browserName
page.goto(server.EMPTY_PAGE).catch(e => {});
const route = await routePromise;
await route.intercept();
// @ts-expect-error
await route._intercept();
try {
await route.continue();
fail('did not throw');
@ -62,7 +64,8 @@ it('should support fulfill after intercept', async ({page, server, browserName,
it.skip(browserName === 'chromium' && browserMajorVersion <= 91);
const requestPromise = server.waitForRequest('/empty.html');
await page.route('**', async route => {
await route.intercept();
// @ts-expect-error
await route._intercept();
await route.fulfill();
});
await page.goto(server.EMPTY_PAGE);
@ -76,7 +79,8 @@ it('should support request overrides', async ({page, server, browserName, browse
it.skip(browserName === 'chromium' && browserMajorVersion <= 91);
const requestPromise = server.waitForRequest('/empty.html');
await page.route('**/foo', async route => {
await route.intercept({
// @ts-expect-error
await route._intercept({
url: server.EMPTY_PAGE,
method: 'POST',
headers: {'foo': 'bar'},
@ -105,7 +109,8 @@ it('should give access to the intercepted response', async ({page, server, brows
const evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/title.html').catch(console.log);
const route = await routePromise;
const response = await route.intercept();
// @ts-expect-error
const response = await route._intercept();
expect(response.status()).toBe(200);
expect(response.ok()).toBeTruthy();
@ -128,7 +133,8 @@ it('should give access to the intercepted response body', async ({page, server,
const evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/simple.json').catch(console.log);
const route = await routePromise;
const response = await route.intercept();
// @ts-expect-error
const response = await route._intercept();
expect((await response.text())).toBe('{"foo": "bar"}\n');
@ -140,7 +146,8 @@ it('should be abortable after interception', async ({page, server, browserName})
it.fixme(browserName === 'webkit');
await page.route(/\.css$/, async route => {
await route.intercept();
// @ts-expect-error
await route._intercept();
await route.abort();
});
let failed = false;

26
types/types.d.ts vendored
View file

@ -10617,32 +10617,6 @@ export interface Route {
status?: number;
}): Promise<void>;
/**
* Continues route's request with optional overrides and intercepts response.
* @param options
*/
intercept(options?: {
/**
* If set changes the request HTTP headers. Header values will be converted to a string.
*/
headers?: { [key: string]: string; };
/**
* If set changes the request method (e.g. GET or POST)
*/
method?: string;
/**
* If set changes the post data of request
*/
postData?: string|Buffer;
/**
* If set changes the request URL. New URL must have same protocol as original one.
*/
url?: string;
}): Promise<Response>;
/**
* A request to be routed.
*/