-
-
Notifications
You must be signed in to change notification settings - Fork 36.6k
perf_hooks: add missing resource timing attributes #65017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
greenheadHQ
wants to merge
3
commits into
nodejs:main
Choose a base branch
from
greenheadHQ:resource-timing-missing-getters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+249
−14
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
test/parallel/test-perf-hooks-resourcetiming-attributes.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
| const assert = require('assert'); | ||
| const { | ||
| PerformanceResourceTiming, | ||
| performance, | ||
| } = require('perf_hooks'); | ||
|
|
||
| // Covers the IDL attributes finalResponseHeadersStart, | ||
| // firstInterimResponseStart, renderBlockingStatus, contentType and contentEncoding, | ||
| // and the spec requirement that responseStart prefers a non-zero | ||
| // firstInterimResponseStart over finalResponseHeadersStart. | ||
|
|
||
| function createTimingInfo(overrides = {}) { | ||
| return { | ||
| startTime: 0, | ||
| redirectStartTime: 0, | ||
| redirectEndTime: 0, | ||
| postRedirectStartTime: 0, | ||
| finalServiceWorkerStartTime: 0, | ||
| finalNetworkRequestStartTime: 0, | ||
| finalNetworkResponseStartTime: 0, | ||
| endTime: 0, | ||
| encodedBodySize: 0, | ||
| decodedBodySize: 0, | ||
| finalConnectionTimingInfo: null, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function markResourceTiming(timingInfo, bodyInfo) { | ||
| return performance.markResourceTiming( | ||
| timingInfo, | ||
| 'http://localhost:8080', | ||
| 'fetch', | ||
| {}, | ||
| '', | ||
| bodyInfo, | ||
| 200, | ||
| '', | ||
| ); | ||
| } | ||
|
|
||
| // Default values with an empty body info, mirroring what the fetch | ||
| // implementation passes for a response with no body metadata. | ||
| { | ||
| const resource = markResourceTiming(createTimingInfo(), {}); | ||
|
|
||
| assert.strictEqual(resource.finalResponseHeadersStart, 0); | ||
| assert.strictEqual(resource.firstInterimResponseStart, 0); | ||
| assert.strictEqual(resource.responseStart, 0); | ||
| assert.strictEqual(resource.renderBlockingStatus, 'non-blocking'); | ||
| assert.strictEqual(resource.contentType, ''); | ||
| assert.strictEqual(resource.contentEncoding, ''); | ||
| } | ||
|
|
||
| // Values reflected from timing info and body info. | ||
| { | ||
| const timingInfo = createTimingInfo({ | ||
| finalNetworkResponseStartTime: 123, | ||
| firstInterimNetworkResponseStartTime: 45, | ||
| renderBlocking: true, | ||
| }); | ||
| const bodyInfo = { | ||
| contentType: 'text/html', | ||
| contentEncoding: 'gzip', | ||
| }; | ||
| const resource = markResourceTiming(timingInfo, bodyInfo); | ||
|
|
||
| assert.strictEqual(resource.finalResponseHeadersStart, 123); | ||
| assert.strictEqual(resource.firstInterimResponseStart, 45); | ||
| assert.strictEqual(resource.responseStart, 45); | ||
| assert.strictEqual(resource.renderBlockingStatus, 'blocking'); | ||
| assert.strictEqual(resource.contentType, 'text/html'); | ||
| assert.strictEqual(resource.contentEncoding, 'gzip'); | ||
|
|
||
| const json = resource.toJSON(); | ||
| assert.strictEqual(json.finalResponseHeadersStart, 123); | ||
| assert.strictEqual(json.firstInterimResponseStart, 45); | ||
| assert.strictEqual(json.responseStart, 45); | ||
| assert.strictEqual(json.renderBlockingStatus, 'blocking'); | ||
| assert.strictEqual(json.contentType, 'text/html'); | ||
| assert.strictEqual(json.contentEncoding, 'gzip'); | ||
| } | ||
|
|
||
| // The attributes are enumerable getters on the prototype and perform a | ||
| // brand check like the other PerformanceResourceTiming attributes. | ||
| for (const name of [ | ||
| 'finalResponseHeadersStart', | ||
| 'firstInterimResponseStart', | ||
| 'renderBlockingStatus', | ||
| 'contentType', | ||
| 'contentEncoding', | ||
| ]) { | ||
| const desc = Object.getOwnPropertyDescriptor( | ||
| PerformanceResourceTiming.prototype, name); | ||
| assert.strictEqual(desc.enumerable, true, name); | ||
| assert.strictEqual(typeof desc.get, 'function', name); | ||
| assert.throws(() => desc.get.call({}), { | ||
| code: 'ERR_INVALID_THIS', | ||
| }, name); | ||
| } | ||
|
|
||
| performance.clearResourceTimings(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added test shows that this property can return a non-zero value even though interim responses are not currently recorded.
This mixes the API's capabilities with current Node.js behavior. The other added properties appear to have the same issue.