Skip to content

Commit

Permalink
fix: fetch resource timing performance entry names should be strings (#…
Browse files Browse the repository at this point in the history
…2188)

* fix: fetch resource timing performance entry names should be strings

* change .toString() to .href
  • Loading branch information
GaryWilber authored Jul 14, 2023
1 parent e22448d commit eb24cc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis, cacheState) {
if (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2)) {
performance.markResourceTiming(timingInfo, originalURL, initiatorType, globalThis, cacheState)
performance.markResourceTiming(timingInfo, originalURL.href, initiatorType, globalThis, cacheState)
}
}

Expand Down
14 changes: 8 additions & 6 deletions test/fetch/resource-timing.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ const {
const skip = nodeMajor < 18 || (nodeMajor === 18 && nodeMinor < 2)

test('should create a PerformanceResourceTiming after each fetch request', { skip }, (t) => {
t.plan(6)
t.plan(8)

const obs = new PerformanceObserver(list => {
const expectedResourceEntryName = `http://localhost:${server.address().port}/`

const entries = list.getEntries()
t.equal(entries.length, 1)
const [entry] = entries
t.same(entry.name, {
href: `http://localhost:${server.address().port}/`,
origin: `http://localhost:${server.address().port}`,
protocol: 'http'
})
t.same(entry.name, expectedResourceEntryName)
t.strictSame(entry.entryType, 'resource')

t.ok(entry.duration >= 0)
t.ok(entry.startTime >= 0)

const entriesByName = list.getEntriesByName(expectedResourceEntryName)
t.equal(entriesByName.length, 1)
t.strictSame(entriesByName[0], entry)

obs.disconnect()
performance.clearResourceTimings()
})
Expand Down

0 comments on commit eb24cc8

Please sign in to comment.