chore: hide request interception for 1.13 (#7425)
This commit is contained in:
parent
9c3ae38914
commit
027fc4c0b4
|
|
@ -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
|
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.
|
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
|
## method: Route.request
|
||||||
- returns: <[Request]>
|
- returns: <[Request]>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
return await this._continue(options, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@ import { test as it, expect } from './pageTest';
|
||||||
it('should fulfill intercepted response', async ({page, server, browserName}) => {
|
it('should fulfill intercepted response', async ({page, server, browserName}) => {
|
||||||
it.fixme(browserName === 'firefox');
|
it.fixme(browserName === 'firefox');
|
||||||
await page.route('**/*', async route => {
|
await page.route('**/*', async route => {
|
||||||
await route.intercept({});
|
// @ts-expect-error
|
||||||
|
await route._intercept({});
|
||||||
await route.fulfill({
|
await route.fulfill({
|
||||||
status: 201,
|
status: 201,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -48,7 +49,8 @@ it('should throw on continue after intercept', async ({page, server, browserName
|
||||||
|
|
||||||
page.goto(server.EMPTY_PAGE).catch(e => {});
|
page.goto(server.EMPTY_PAGE).catch(e => {});
|
||||||
const route = await routePromise;
|
const route = await routePromise;
|
||||||
await route.intercept();
|
// @ts-expect-error
|
||||||
|
await route._intercept();
|
||||||
try {
|
try {
|
||||||
await route.continue();
|
await route.continue();
|
||||||
fail('did not throw');
|
fail('did not throw');
|
||||||
|
|
@ -62,7 +64,8 @@ it('should support fulfill after intercept', async ({page, server, browserName,
|
||||||
it.skip(browserName === 'chromium' && browserMajorVersion <= 91);
|
it.skip(browserName === 'chromium' && browserMajorVersion <= 91);
|
||||||
const requestPromise = server.waitForRequest('/empty.html');
|
const requestPromise = server.waitForRequest('/empty.html');
|
||||||
await page.route('**', async route => {
|
await page.route('**', async route => {
|
||||||
await route.intercept();
|
// @ts-expect-error
|
||||||
|
await route._intercept();
|
||||||
await route.fulfill();
|
await route.fulfill();
|
||||||
});
|
});
|
||||||
await page.goto(server.EMPTY_PAGE);
|
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);
|
it.skip(browserName === 'chromium' && browserMajorVersion <= 91);
|
||||||
const requestPromise = server.waitForRequest('/empty.html');
|
const requestPromise = server.waitForRequest('/empty.html');
|
||||||
await page.route('**/foo', async route => {
|
await page.route('**/foo', async route => {
|
||||||
await route.intercept({
|
// @ts-expect-error
|
||||||
|
await route._intercept({
|
||||||
url: server.EMPTY_PAGE,
|
url: server.EMPTY_PAGE,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'foo': 'bar'},
|
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 evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/title.html').catch(console.log);
|
||||||
|
|
||||||
const route = await routePromise;
|
const route = await routePromise;
|
||||||
const response = await route.intercept();
|
// @ts-expect-error
|
||||||
|
const response = await route._intercept();
|
||||||
|
|
||||||
expect(response.status()).toBe(200);
|
expect(response.status()).toBe(200);
|
||||||
expect(response.ok()).toBeTruthy();
|
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 evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/simple.json').catch(console.log);
|
||||||
|
|
||||||
const route = await routePromise;
|
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');
|
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');
|
it.fixme(browserName === 'webkit');
|
||||||
|
|
||||||
await page.route(/\.css$/, async route => {
|
await page.route(/\.css$/, async route => {
|
||||||
await route.intercept();
|
// @ts-expect-error
|
||||||
|
await route._intercept();
|
||||||
await route.abort();
|
await route.abort();
|
||||||
});
|
});
|
||||||
let failed = false;
|
let failed = false;
|
||||||
|
|
|
||||||
26
types/types.d.ts
vendored
26
types/types.d.ts
vendored
|
|
@ -10617,32 +10617,6 @@ export interface Route {
|
||||||
status?: number;
|
status?: number;
|
||||||
}): Promise<void>;
|
}): 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.
|
* A request to be routed.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue