From 027fc4c0b48ff8b1327048c6b1f962a8371c75a8 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 1 Jul 2021 18:33:47 +0200 Subject: [PATCH] chore: hide request interception for 1.13 (#7425) --- docs/src/api/class-route.md | 25 ---------------------- src/client/network.ts | 2 +- tests/page/page-request-intercept.spec.ts | 21 ++++++++++++------ types/types.d.ts | 26 ----------------------- 4 files changed, 15 insertions(+), 59 deletions(-) diff --git a/docs/src/api/class-route.md b/docs/src/api/class-route.md index 72487b7195..639324bb2f 100644 --- a/docs/src/api/class-route.md +++ b/docs/src/api/class-route.md @@ -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]> diff --git a/src/client/network.ts b/src/client/network.ts index 1955582adc..e7236b28f8 100644 --- a/src/client/network.ts +++ b/src/client/network.ts @@ -302,7 +302,7 @@ export class Route extends ChannelOwner { + async _intercept(options: { url?: string, method?: string, headers?: Headers, postData?: string | Buffer, interceptResponse?: boolean } = {}): Promise { return await this._continue(options, true); } diff --git a/tests/page/page-request-intercept.spec.ts b/tests/page/page-request-intercept.spec.ts index f0ff34d894..da2178f716 100644 --- a/tests/page/page-request-intercept.spec.ts +++ b/tests/page/page-request-intercept.spec.ts @@ -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; diff --git a/types/types.d.ts b/types/types.d.ts index 9f0baf327a..90d47f1f50 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -10617,32 +10617,6 @@ export interface Route { status?: number; }): Promise; - /** - * 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; - /** * A request to be routed. */