Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: hide Route.fulfill._response from API (#8483)
Max Schmitt998f2ab95944
diff --git a/docs/src/api/class-route.md b/docs/src/api/class-route.mdindex f096db67b9..aabcd7560f 100644--- a/docs/src/api/class-route.md+++ b/docs/src/api/class-route.md@@ -181,11 +181,6 @@ page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json")await page.RouteAsync("**/xhr_endpoint", route => route.FulfillAsync(new RouteFulfillOptions { Path = "mock_data.json" }));```-### option: Route.fulfill._response-- `_response` <[Response]>--Intercepted response. Will be used to populate all response fields not explicitely overridden.-### option: Route.fulfill.status- `status` <[int]>diff --git a/src/client/network.ts b/src/client/network.tsindex e5f4dc4509..e148d09bb4 100644--- a/src/client/network.ts+++ b/src/client/network.ts@@ -267,18 +267,18 @@ export class Route extends ChannelOwner<channels.RouteChannel, channels.RouteIni});}- async fulfill(options: { _response?: Response, status?: number, headers?: Headers, contentType?: string, body?: string | Buffer, path?: string } = {}) {+ async fulfill(options: { response?: Response, status?: number, headers?: Headers, contentType?: string, body?: string | Buffer, path?: string } = {}) {return this._wrapApiCall(async (channel: channels.RouteChannel) => {let useInterceptedResponseBody;let { status: statusOption, headers: headersOption, body: bodyOption } = options;- if (options._response) {- statusOption ||= options._response.status();- headersOption ||= options._response.headers();+ if (options.response) {+ statusOption ||= options.response.status();+ headersOption ||= options.response.headers();if (options.body === undefined && options.path === undefined) {- if (options._response === this._interceptedResponse)+ if (options.response === this._interceptedResponse)useInterceptedResponseBody = true;else- bodyOption = await options._response.body();+ bodyOption = await options.response.body();}}diff --git a/tests/page/page-request-intercept.spec.ts b/tests/page/page-request-intercept.spec.tsindex 260fb85826..25462f18c4 100644--- a/tests/page/page-request-intercept.spec.ts+++ b/tests/page/page-request-intercept.spec.ts@@ -44,9 +44,10 @@ it('should fulfill response with empty body', async ({page, server, browserName,it.skip(browserName === 'chromium' && browserMajorVersion <= 91, 'Fails in Electron that uses old Chromium');await page.route('**/*', async route => {// @ts-expect-error- const _response = await route._continueToResponse({});+ const response = await route._continueToResponse({});await route.fulfill({- _response,+ // @ts-expect-error+ response,status: 201,body: ''});@@ -92,7 +93,8 @@ it('should fulfill with any response', async ({page, server, browserName, browse// @ts-expect-errorawait route._continueToResponse({});await route.fulfill({- _response: sampleResponse,+ // @ts-expect-error+ response: sampleResponse,status: 201,contentType: 'text/plain'});@@ -124,8 +126,9 @@ it('should support fulfill after intercept', async ({page, server}) => {const requestPromise = server.waitForRequest('/title.html');await page.route('**', async route => {// @ts-expect-error- const _response = await route._continueToResponse();- await route.fulfill({ _response });+ const response = await route._continueToResponse();+ // @ts-expect-error+ await route.fulfill({ response });});const response = await page.goto(server.PREFIX + '/title.html');const request = await requestPromise;@@ -143,8 +146,9 @@ it('should intercept failures', async ({page, browserName, browserMajorVersion,await page.route('**', async route => {try {// @ts-expect-error- const _response = await route._continueToResponse();- await route.fulfill({ _response });+ const response = await route._continueToResponse();+ // @ts-expect-error+ await route.fulfill({ response });} catch (e) {error = e;}@@ -163,13 +167,14 @@ it('should support request overrides', async ({page, server, browserName, browseconst requestPromise = server.waitForRequest('/empty.html');await page.route('**/foo', async route => {// @ts-expect-error- const _response = await route._continueToResponse({+ const response = await route._continueToResponse({url: server.EMPTY_PAGE,method: 'POST',headers: {'foo': 'bar'},postData: 'my data',});- await route.fulfill({ _response });+ // @ts-expect-error+ await route.fulfill({ response });});await page.goto(server.PREFIX + '/foo');const request = await requestPromise;@@ -197,7 +202,8 @@ it('should give access to the intercepted response', async ({page, server}) => {expect(response.url()).toBe(server.PREFIX + '/title.html');expect(response.headers()['content-type']).toBe('text/html; charset=utf-8');- await Promise.all([route.fulfill({ _response: response }), evalPromise]);+ // @ts-expect-error+ await Promise.all([route.fulfill({ response }), evalPromise]);});it('should give access to the intercepted response status text', async ({page, server, browserName}) => {@@ -220,7 +226,8 @@ it('should give access to the intercepted response status text', async ({page, sexpect(response.statusText()).toBe('You are awesome');expect(response.url()).toBe(server.PREFIX + '/title.html');- await Promise.all([route.fulfill({ _response: response }), evalPromise]);+ // @ts-expect-error+ await Promise.all([route.fulfill({ response }), evalPromise]);});it('should give access to the intercepted response body', async ({page, server}) => {@@ -238,7 +245,8 @@ it('should give access to the intercepted response body', async ({page, server})expect((await response.text())).toBe('{"foo": "bar"}\n');- await Promise.all([route.fulfill({ _response: response }), evalPromise]);+ // @ts-expect-error+ await Promise.all([route.fulfill({ response }), evalPromise]);});it('should be abortable after interception', async ({page, server, browserName}) => {@@ -314,8 +322,9 @@ it('should fulfill original response after redirects', async ({page, browserNameawait page.route('**/*', async route => {++routeCalls;// @ts-expect-error- const _response = await route._continueToResponse({});- await route.fulfill({ _response });+ const response = await route._continueToResponse({});+ // @ts-expect-error+ await route.fulfill({ response });});const response = await page.goto(server.PREFIX + '/redirect/1.html');expect(requestUrls).toEqual(expectedUrls);diff --git a/types/types.d.ts b/types/types.d.tsindex 29f2cf7917..abd8e7d781 100644--- a/types/types.d.ts+++ b/types/types.d.ts@@ -11940,11 +11940,6 @@ export interface Route {* @param options*/fulfill(options?: {- /**- * Intercepted response. Will be used to populate all response fields not explicitely overridden.- */- _response?: Response;-/*** Response body.*/