fix(connect): make route.fulfill({ response }) work (#12006)
This commit is contained in:
parent
9287ef2dfb
commit
9c66068971
|
|
@ -220,7 +220,7 @@ export class APIRequestContext extends ChannelOwner<channels.APIRequestContextCh
|
|||
export class APIResponse implements api.APIResponse {
|
||||
private readonly _initializer: channels.APIResponse;
|
||||
private readonly _headers: RawHeaders;
|
||||
private readonly _request: APIRequestContext;
|
||||
readonly _request: APIRequestContext;
|
||||
|
||||
constructor(context: APIRequestContext, initializer: channels.APIResponse) {
|
||||
this._request = context;
|
||||
|
|
|
|||
|
|
@ -245,8 +245,12 @@ export class Route extends ChannelOwner<channels.RouteChannel> implements api.Ro
|
|||
if (options.response) {
|
||||
statusOption ||= options.response.status();
|
||||
headersOption ||= options.response.headers();
|
||||
if (options.body === undefined && options.path === undefined && options.response instanceof APIResponse)
|
||||
fetchResponseUid = (options.response as APIResponse)._fetchUid();
|
||||
if (options.body === undefined && options.path === undefined && options.response instanceof APIResponse) {
|
||||
if (options.response._request._connection === this._connection)
|
||||
fetchResponseUid = (options.response as APIResponse)._fetchUid();
|
||||
else
|
||||
body = await options.response.body();
|
||||
}
|
||||
}
|
||||
|
||||
let isBase64 = false;
|
||||
|
|
|
|||
|
|
@ -555,3 +555,19 @@ test('should record trace with sources', async ({ browserType, startRemoteServer
|
|||
const thisFile = await fs.promises.readFile(__filename);
|
||||
expect(sourceFile).toEqual(thisFile);
|
||||
});
|
||||
|
||||
test('should fulfill with global fetch result', async ({ browserType, startRemoteServer, playwright, server }) => {
|
||||
const remoteServer = await startRemoteServer();
|
||||
const browser = await browserType.connect(remoteServer.wsEndpoint());
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
|
||||
await page.route('**/*', async route => {
|
||||
const request = await playwright.request.newContext();
|
||||
const response = await request.get(server.PREFIX + '/simple.json');
|
||||
route.fulfill({ response });
|
||||
});
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.status()).toBe(200);
|
||||
expect(await response.json()).toEqual({ 'foo': 'bar' });
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue