fix: fix har entry time calculation (#6472)
This commit is contained in:
parent
33823a9143
commit
1c10c4cbe8
|
|
@ -186,14 +186,20 @@ export class HarTracer {
|
|||
const timing = response.timing();
|
||||
if (pageEntry.startedDateTime.valueOf() > timing.startTime)
|
||||
pageEntry.startedDateTime = new Date(timing.startTime);
|
||||
const dns = timing.domainLookupEnd !== -1 ? helper.millisToRoundishMillis(timing.domainLookupEnd - timing.domainLookupStart) : -1;
|
||||
const connect = timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.connectStart) : -1;
|
||||
const ssl = timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.secureConnectionStart) : -1;
|
||||
const wait = timing.responseStart !== -1 ? helper.millisToRoundishMillis(timing.responseStart - timing.requestStart) : -1;
|
||||
const receive = response.request()._responseEndTiming !== -1 ? helper.millisToRoundishMillis(response.request()._responseEndTiming - timing.responseStart) : -1;
|
||||
harEntry.timings = {
|
||||
dns: timing.domainLookupEnd !== -1 ? helper.millisToRoundishMillis(timing.domainLookupEnd - timing.domainLookupStart) : -1,
|
||||
connect: timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.connectStart) : -1,
|
||||
ssl: timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.secureConnectionStart) : -1,
|
||||
dns,
|
||||
connect,
|
||||
ssl,
|
||||
send: 0,
|
||||
wait: timing.responseStart !== -1 ? helper.millisToRoundishMillis(timing.responseStart - timing.requestStart) : -1,
|
||||
receive: response.request()._responseEndTiming !== -1 ? helper.millisToRoundishMillis(response.request()._responseEndTiming - timing.responseStart) : -1,
|
||||
wait,
|
||||
receive,
|
||||
};
|
||||
harEntry.time = [dns, connect, ssl, wait, receive].reduce((pre, cur) => cur > 0 ? cur + pre : pre, 0);
|
||||
if (!this._options.omitContent && response.status() === 200) {
|
||||
const promise = response.body().then(buffer => {
|
||||
harEntry.response.content.text = buffer.toString('base64');
|
||||
|
|
|
|||
|
|
@ -251,3 +251,10 @@ it('should include content', async ({ contextFactory, server }, testInfo) => {
|
|||
expect(content2.mimeType).toBe('text/css; charset=utf-8');
|
||||
expect(Buffer.from(content2.text, 'base64').toString()).toContain('pink');
|
||||
});
|
||||
|
||||
it('should calculate time', async ({ contextFactory, server }, testInfo) => {
|
||||
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
|
||||
await page.goto(server.PREFIX + '/har.html');
|
||||
const log = await getLog();
|
||||
expect(log.entries[0].time).toBeGreaterThan(0);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue