Skip to content

Commit

Permalink
core(server-response-time): use receiveHeadersStart instead of end (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Jun 12, 2023
1 parent 0464a56 commit fe61d6a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/audits/server-response-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ServerResponseTime extends Audit {
*/
static calculateResponseTime(record) {
const timing = record.timing;
return timing ? timing.receiveHeadersEnd - timing.sendEnd : 0;
return timing ? timing.receiveHeadersStart - timing.sendEnd : 0;
}

/**
Expand Down
29 changes: 28 additions & 1 deletion core/test/audits/server-response-time-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Performance: server-response-time audit', () => {
const mainResource = {
url: 'https://example.com/',
requestId: '0',
timing: {receiveHeadersEnd: 830, sendEnd: 200},
timing: {receiveHeadersStart: 830, sendEnd: 200},
};
const devtoolsLog = networkRecordsToDevtoolsLog([mainResource]);

Expand All @@ -37,6 +37,33 @@ describe('Performance: server-response-time audit', () => {
});

it('succeeds when response time of root document is lower than 600ms', async () => {
const mainResource = {
url: 'https://example.com/',
requestId: '0',
timing: {receiveHeadersStart: 400, sendEnd: 200},
};
const devtoolsLog = networkRecordsToDevtoolsLog([mainResource]);

const artifacts = {
devtoolsLogs: {[ServerResponseTime.DEFAULT_PASS]: devtoolsLog},
URL: {mainDocumentUrl: 'https://example.com/'},
GatherContext: {gatherMode: 'navigation'},
};

const result = await ServerResponseTime.audit(artifacts, {computedCache: new Map()});
expect(result).toMatchObject({
numericValue: 200,
score: 1,
metricSavings: {
FCP: 100,
LCP: 100,
},
});
});

// TODO(compat): remove M116. See _backfillReceiveHeaderStartTiming.
// eslint-disable-next-line max-len
it('succeeds when response time of root document is lower than 600ms (receiveHeadersEnd fallback)', async () => {
const mainResource = {
url: 'https://example.com/',
requestId: '0',
Expand Down

0 comments on commit fe61d6a

Please sign in to comment.