startAt needs to be walltime

This commit is contained in:
Simon Knott 2024-09-18 15:51:19 +02:00
parent 7a251be356
commit b717257013
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 3 additions and 1 deletions

View file

@ -302,6 +302,7 @@ export abstract class APIRequestContext extends SdkObject {
const requestOptions = { ...options, agent }; const requestOptions = { ...options, agent };
const startAt = monotonicTime(); const startAt = monotonicTime();
const startAtWallTime = Date.now();
let dnsLookupAt: number | undefined; let dnsLookupAt: number | undefined;
let tcpConnectionAt: number | undefined; let tcpConnectionAt: number | undefined;
let tlsHandshakeAt: number | undefined; let tlsHandshakeAt: number | undefined;
@ -441,7 +442,7 @@ export abstract class APIRequestContext extends SdkObject {
const endAt = monotonicTime(); const endAt = monotonicTime();
// spec: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming // spec: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming
const timing: channels.ResourceTiming = { const timing: channels.ResourceTiming = {
startTime: startAt, startTime: startAtWallTime,
domainLookupStart: dnsLookupAt ? 0 : -1, domainLookupStart: dnsLookupAt ? 0 : -1,
domainLookupEnd: dnsLookupAt ? dnsLookupAt! - startAt : -1, domainLookupEnd: dnsLookupAt ? dnsLookupAt! - startAt : -1,
connectStart: dnsLookupAt ? dnsLookupAt! - startAt : 0, connectStart: dnsLookupAt ? dnsLookupAt! - startAt : 0,

View file

@ -63,6 +63,7 @@ it('fetch should work', async ({ context, server }) => {
secureConnectionStart: expect.any(Number), secureConnectionStart: expect.any(Number),
startTime: expect.any(Number), startTime: expect.any(Number),
}); });
expect(response.timing().startTime, 'is right order of magnitude').toBeCloseTo(Date.now(), -3);
expect(await response.text()).toBe('{"foo": "bar"}\n'); expect(await response.text()).toBe('{"foo": "bar"}\n');
}); });