Skip to content

Commit dc51536

Browse files
authored
feat(waitForResponse): print regex pattern when waiting for request/response (#5485)
1 parent 8c18b90 commit dc51536

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/client/page.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
368368
return urlOrPredicate(request);
369369
};
370370
const trimmedUrl = trimUrl(urlOrPredicate);
371-
const logLine = trimmedUrl ? `waiting for request "${trimmedUrl}"` : undefined;
371+
const logLine = trimmedUrl ? `waiting for request ${trimmedUrl}` : undefined;
372372
return this._waitForEvent(Events.Page.Request, { predicate, timeout: options.timeout }, logLine);
373373
});
374374
}
@@ -381,7 +381,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
381381
return urlOrPredicate(response);
382382
};
383383
const trimmedUrl = trimUrl(urlOrPredicate);
384-
const logLine = trimmedUrl ? `waiting for response "${trimmedUrl}"` : undefined;
384+
const logLine = trimmedUrl ? `waiting for response ${trimmedUrl}` : undefined;
385385
return this._waitForEvent(Events.Page.Response, { predicate, timeout: options.timeout }, logLine);
386386
});
387387
}
@@ -699,10 +699,15 @@ export class BindingCall extends ChannelOwner<channels.BindingCallChannel, chann
699699
}
700700
}
701701

702+
function trimEnd(s: string): string {
703+
if (s.length > 50)
704+
s = s.substring(0, 50) + '\u2026';
705+
return s;
706+
}
707+
702708
function trimUrl(param: any): string | undefined {
703-
if (isString(param)) {
704-
if (param.length > 50)
705-
param = param.substring(0, 50) + '\u2026';
706-
return param;
707-
}
709+
if (isRegExp(param))
710+
return `/${trimEnd(param.source)}/${param.flags}`;
711+
if (isString(param))
712+
return `"${trimEnd(param)}"`;
708713
}

test/page-wait-for-response.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ it('should respect default timeout', async ({page, playwright}) => {
4444
});
4545

4646
it('should log the url', async ({page}) => {
47-
const error = await page.waitForResponse('foo.css', { timeout: 100 }).catch(e => e);
48-
expect(error.message).toContain('waiting for response "foo.css"');
47+
const error1 = await page.waitForResponse('foo.css', { timeout: 100 }).catch(e => e);
48+
expect(error1.message).toContain('waiting for response "foo.css"');
49+
const error2 = await page.waitForResponse(/foo.css/i, { timeout: 100 }).catch(e => e);
50+
expect(error2.message).toContain('waiting for response /foo.css/i');
4951
});
5052

5153
it('should work with predicate', async ({page, server}) => {

0 commit comments

Comments
 (0)