From 71c3605a0e3321590cef51b2c177932fe66d2a1a Mon Sep 17 00:00:00 2001 From: Amila Welihinda Date: Fri, 3 Mar 2023 21:36:04 -0800 Subject: [PATCH] fix: correctly calculate resource timing duration (#1988) --- lib/fetch/index.js | 2 +- test/fetch/resource-timing.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 6e356de8128..e3834a7f1c6 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -297,7 +297,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') { // capability. // TODO: given global’s relevant settings object’s cross-origin isolated // capability? - response.timingInfo.endTime = coarsenedSharedCurrentTime() + timingInfo.endTime = coarsenedSharedCurrentTime() // 10. Set response’s timing info to timingInfo. response.timingInfo = timingInfo diff --git a/test/fetch/resource-timing.js b/test/fetch/resource-timing.js index c8732198c30..885e3b3c171 100644 --- a/test/fetch/resource-timing.js +++ b/test/fetch/resource-timing.js @@ -13,7 +13,7 @@ const { const skip = nodeMajor < 18 || (nodeMajor === 18 && nodeMinor < 2) test('should create a PerformanceResourceTiming after each fetch request', { skip }, (t) => { - t.plan(4) + t.plan(6) const obs = new PerformanceObserver(list => { const entries = list.getEntries() t.equal(entries.length, 1) @@ -25,6 +25,9 @@ test('should create a PerformanceResourceTiming after each fetch request', { ski }) t.strictSame(entry.entryType, 'resource') + t.ok(entry.duration >= 0) + t.ok(entry.startTime >= 0) + obs.disconnect() performance.clearResourceTimings() })