feat(har): add _requestref (#8847)

This commit is contained in:
Ross Wollman 2021-09-11 17:25:00 -07:00 committed by GitHub
parent 798d0bfa9b
commit 549411dc33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 0 deletions

View File

@ -55,6 +55,7 @@ export type Entry = {
timings: Timings;
serverIPAddress?: string;
connection?: string;
_requestref: string;
_frameref: string;
_monotonicTime: number;
_serverPort?: number;

View File

@ -141,6 +141,7 @@ export class HarTracer {
const pageEntry = this._ensurePageEntry(page);
const harEntry: har.Entry = {
pageref: pageEntry.id,
_requestref: request.guid,
_frameref: request.frame().guid,
_monotonicTime: monotonicTime(),
startedDateTime: new Date(),

View File

@ -589,3 +589,42 @@ it('should have different hars for concurrent contexts', async ({ contextFactory
expect(pageEntry.title).toBe('One');
}
});
it('should include _requestref', async ({ contextFactory, server }, testInfo) => {
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
const resp = await page.goto(server.EMPTY_PAGE);
const log = await getLog();
expect(log.entries.length).toBe(1);
const entry = log.entries[0];
expect(entry._requestref).toMatch(/^request@[a-f0-9]{32}$/);
expect(entry._requestref).toBe((resp.request() as any)._guid);
});
it('should include _requestref for redirects', async ({ contextFactory, server }, testInfo) => {
server.setRedirect('/start', '/one-more');
server.setRedirect('/one-more', server.EMPTY_PAGE);
const { page, getLog, context } = await pageWithHar(contextFactory, testInfo);
const requests = new Map<string, string>();
context.on('request', request => {
requests.set(request.url(), (request as any)._guid);
});
await page.goto(server.PREFIX + '/start');
const log = await getLog();
expect(log.entries.length).toBe(3);
const entryStart = log.entries[0];
expect(entryStart.request.url).toBe(server.PREFIX + '/start');
expect(entryStart._requestref).toBe(requests.get(entryStart.request.url));
const entryOneMore = log.entries[1];
expect(entryOneMore.request.url).toBe(server.PREFIX + '/one-more');
expect(entryOneMore._requestref).toBe(requests.get(entryOneMore.request.url));
const entryEmptyPage = log.entries[2];
expect(entryEmptyPage.request.url).toBe(server.EMPTY_PAGE);
expect(entryEmptyPage._requestref).toBe(requests.get(entryEmptyPage.request.url));
});