feat(waitForResponse): print regex pattern when waiting for request/response (#5485)
This commit is contained in:
parent
8c18b90038
commit
dc51536bca
|
|
@ -368,7 +368,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
|
|||
return urlOrPredicate(request);
|
||||
};
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
@ -381,7 +381,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
|
|||
return urlOrPredicate(response);
|
||||
};
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
@ -699,10 +699,15 @@ export class BindingCall extends ChannelOwner<channels.BindingCallChannel, chann
|
|||
}
|
||||
}
|
||||
|
||||
function trimUrl(param: any): string | undefined {
|
||||
if (isString(param)) {
|
||||
if (param.length > 50)
|
||||
param = param.substring(0, 50) + '\u2026';
|
||||
return param;
|
||||
}
|
||||
function trimEnd(s: string): string {
|
||||
if (s.length > 50)
|
||||
s = s.substring(0, 50) + '\u2026';
|
||||
return s;
|
||||
}
|
||||
|
||||
function trimUrl(param: any): string | undefined {
|
||||
if (isRegExp(param))
|
||||
return `/${trimEnd(param.source)}/${param.flags}`;
|
||||
if (isString(param))
|
||||
return `"${trimEnd(param)}"`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,8 +44,10 @@ it('should respect default timeout', async ({page, playwright}) => {
|
|||
});
|
||||
|
||||
it('should log the url', async ({page}) => {
|
||||
const error = await page.waitForResponse('foo.css', { timeout: 100 }).catch(e => e);
|
||||
expect(error.message).toContain('waiting for response "foo.css"');
|
||||
const error1 = await page.waitForResponse('foo.css', { timeout: 100 }).catch(e => e);
|
||||
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}) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue