feat(trace): include url into route.fulfill call params (#16934)

This commit is contained in:
Yury Semikhatsky 2022-08-31 12:37:49 -07:00 committed by GitHub
parent 9f51af5583
commit aaa28394cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 2 deletions

View File

@ -128,6 +128,8 @@ export class RouteDispatcher extends Dispatcher<Route, channels.RouteChannel, Re
}
async continue(params: channels.RouteContinueParams, metadata: CallMetadata): Promise<channels.RouteContinueResult> {
// Used to discriminate between continue in tracing.
metadata.params.requestUrl = this._object.request().url();
await this._object.continue({
url: params.url,
method: params.method,
@ -136,11 +138,15 @@ export class RouteDispatcher extends Dispatcher<Route, channels.RouteChannel, Re
});
}
async fulfill(params: channels.RouteFulfillParams): Promise<void> {
async fulfill(params: channels.RouteFulfillParams, metadata: CallMetadata): Promise<void> {
// Used to discriminate between fulfills in tracing.
metadata.params.requestUrl = this._object.request().url();
await this._object.fulfill(params);
}
async abort(params: channels.RouteAbortParams): Promise<void> {
async abort(params: channels.RouteAbortParams, metadata: CallMetadata): Promise<void> {
// Used to discriminate between abort in tracing.
metadata.params.requestUrl = this._object.request().url();
await this._object.abort(params.errorCode || 'failed');
}

View File

@ -633,3 +633,56 @@ test('should open two trace files', async ({ context, page, request, server, sho
await expect(callLine.locator('text=events')).toHaveText(/events: [\d]+/);
});
test('should include requestUrl in route.fulfill', async ({ page, runAndTrace, browserName }) => {
await page.route('**/*', route => {
route.fulfill({
status: 200,
headers: {
'content-type': 'text/html'
},
body: 'Hello there!'
});
});
const traceViewer = await runAndTrace(async () => {
await page.goto('http://test.com');
});
// Render snapshot, check expectations.
await traceViewer.selectAction('route.fulfill');
await traceViewer.page.locator('.tab-label', { hasText: 'Call' }).click();
const callLine = traceViewer.page.locator('.call-line');
await expect(callLine.locator('text=status')).toContainText('200');
await expect(callLine.locator('text=requestUrl')).toContainText('http://test.com');
});
test('should include requestUrl in route.continue', async ({ page, runAndTrace, server }) => {
await page.route('**/*', route => {
route.continue({ url: server.EMPTY_PAGE });
});
const traceViewer = await runAndTrace(async () => {
await page.goto('http://test.com');
});
// Render snapshot, check expectations.
await traceViewer.selectAction('route.continue');
await traceViewer.page.locator('.tab-label', { hasText: 'Call' }).click();
const callLine = traceViewer.page.locator('.call-line');
await expect(callLine.locator('text=requestUrl')).toContainText('http://test.com');
await expect(callLine.locator('text=/^url: .*/')).toContainText(server.EMPTY_PAGE);
});
test('should include requestUrl in route.abort', async ({ page, runAndTrace, server }) => {
await page.route('**/*', route => {
route.abort();
});
const traceViewer = await runAndTrace(async () => {
await page.goto('http://test.com').catch(() => {});
});
// Render snapshot, check expectations.
await traceViewer.selectAction('route.abort');
await traceViewer.page.locator('.tab-label', { hasText: 'Call' }).click();
const callLine = traceViewer.page.locator('.call-line');
await expect(callLine.locator('text=requestUrl')).toContainText('http://test.com');
});