feat(waitForResponse): print regex pattern when waiting for request/response (#5485)

This commit is contained in:
Dmitry Gozman 2021-02-17 15:11:23 -08:00 committed by GitHub
parent 8c18b90038
commit dc51536bca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -368,7 +368,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
return urlOrPredicate(request); return urlOrPredicate(request);
}; };
const trimmedUrl = trimUrl(urlOrPredicate); const trimmedUrl = trimUrl(urlOrPredicate);
const logLine = trimmedUrl ? `waiting for request "${trimmedUrl}"` : undefined; const logLine = trimmedUrl ? `waiting for request ${trimmedUrl}` : undefined;
return this._waitForEvent(Events.Page.Request, { predicate, timeout: options.timeout }, logLine); return this._waitForEvent(Events.Page.Request, { predicate, timeout: options.timeout }, logLine);
}); });
} }
@ -381,7 +381,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
return urlOrPredicate(response); return urlOrPredicate(response);
}; };
const trimmedUrl = trimUrl(urlOrPredicate); const trimmedUrl = trimUrl(urlOrPredicate);
const logLine = trimmedUrl ? `waiting for response "${trimmedUrl}"` : undefined; const logLine = trimmedUrl ? `waiting for response ${trimmedUrl}` : undefined;
return this._waitForEvent(Events.Page.Response, { predicate, timeout: options.timeout }, logLine); return this._waitForEvent(Events.Page.Response, { predicate, timeout: options.timeout }, logLine);
}); });
} }
@ -699,10 +699,15 @@ export class BindingCall extends ChannelOwner<channels.BindingCallChannel, chann
} }
} }
function trimUrl(param: any): string | undefined { function trimEnd(s: string): string {
if (isString(param)) { if (s.length > 50)
if (param.length > 50) s = s.substring(0, 50) + '\u2026';
param = param.substring(0, 50) + '\u2026'; return s;
return param; }
}
function trimUrl(param: any): string | undefined {
if (isRegExp(param))
return `/${trimEnd(param.source)}/${param.flags}`;
if (isString(param))
return `"${trimEnd(param)}"`;
} }

View file

@ -44,8 +44,10 @@ it('should respect default timeout', async ({page, playwright}) => {
}); });
it('should log the url', async ({page}) => { it('should log the url', async ({page}) => {
const error = await page.waitForResponse('foo.css', { timeout: 100 }).catch(e => e); const error1 = await page.waitForResponse('foo.css', { timeout: 100 }).catch(e => e);
expect(error.message).toContain('waiting for response "foo.css"'); expect(error1.message).toContain('waiting for response "foo.css"');
const error2 = await page.waitForResponse(/foo.css/i, { timeout: 100 }).catch(e => e);
expect(error2.message).toContain('waiting for response /foo.css/i');
}); });
it('should work with predicate', async ({page, server}) => { it('should work with predicate', async ({page, server}) => {