-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
report(redirects): reformat results, incl all requests and wasted time, #3492
Conversation
lighthouse-core/audits/redirects.js
Outdated
|
||
// Only create a table (with the initial request) if there are > 1 redirects | ||
if (!initialRequest) { | ||
if (redirectRequests.length > 1) { |
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.
This >1
and a === 2
below could instead use a ACCEPTED_REDIRECTS
const if folks prefer.
startTime: 17, | ||
url: 'http://exampel.com/', |
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.
typo example.com?
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.
this was deliberate. :)
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.
Looks good, thanks for cleaning up! Really appreciate it! 🥇
Just a few remarks about urls and spelling 😄
startTime: 12, | ||
url: 'https://m.example.com/', | ||
}, | ||
], | ||
}; | ||
|
||
const FAILING_TWO_REDIRECTS = { | ||
startTime: 446.286, | ||
url: 'http://lisairish.com/', |
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.
perhaps better to just use example.com as an url so it's consistent with the rest?
Or is this a marketing stunt for your mom's website? 😆
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.
Well i tested this with these actual URLs, which have this set of redirects setup.
lighthouse-core/audits/redirects.js
Outdated
{key: 'wastedMs', itemType: 'text', text: 'Time for Redirect'}, | ||
]; | ||
const details = Audit.makeTableDetails(headings, pageRedirects); | ||
|
||
return { | ||
score: UnusedBytes.scoreForWastedMs(totalWastedMs), | ||
// We award a passing grade if you only have 1 redirect | ||
score: redirectRequests.length === 2 ? 100 : UnusedBytes.scoreForWastedMs(totalWastedMs), |
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.
if totalWastedMs === 0
scoreForWastedMs doesn't already give you a 100?
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.
With the new logic you can get totalWastedMs > 0
and still get a passing grade. Take http://www.lisairish.com which i was seeing it take 500ms to redirect to https://www.lisairish.com. We should still tell them about the 500ms even if we pass them.
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.
could we add a passing test case for a resource with 0 redirects too? I had to pause for a second on this, alternatively switch to redirectRequests.length <= 2
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.
already have passing test case for 0 redirects.
changed to <= 2
.
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.
need to update the smoke test expectations for the additional URL in the details list. Not sure about the other failure though...was that expected?
ah, yes, it was:
|
lighthouse-core/audits/redirects.js
Outdated
// We allow 1 redirect (www. => m.) | ||
if (i > 1) { | ||
totalWastedMs += wastedMs; | ||
for (let i = 0; i < redirectRequests.length; i++) { |
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 if (!initialRequest)
part of this ends up being a little confusing. What about pulling it out, something like
let totalWastedMs = 0;
const pageRedirects = [];
if (redirectRequests.length > 1) {
pageRedirects.push({
url: `(Initial: ${redirectRequests[0].url})`,
wastedMs: 'n/a',
});
}
for (let i = 1; i < redirectRequests.length; i++) {
const initialRequest = redirectRequests[i - 1];
const redirectedRequest = redirectRequests[i];
const wastedMs = (redirectedRequest.startTime - initialRequest.startTime) * 1000;
totalWastedMs += wastedMs;
pageRedirects.push({
url: redirectedRequest.url,
wastedMs: Util.formatMilliseconds(wastedMs, 1),
});
}
(I believe that should be equivalent)
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.
+1
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.
sg thx
updated! @brendankenny ptal. |
will you rebase to pick up the passive event listener fix? |
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.
ptal :)
714bbad
to
0b032a9
Compare
@brendankenny thar u go |
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.
LGTM, sorry I missed your rebase!
@patrickhulce if you have any last issues |
assert.equal(output.details.items.length, 4); | ||
assert.equal(output.rawValue, 17000); | ||
}); | ||
}); |
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.
nit: add newline
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.
lgtm % nits
lighthouse-core/audits/redirects.js
Outdated
{key: 'wastedMs', itemType: 'text', text: 'Time for Redirect'}, | ||
]; | ||
const details = Audit.makeTableDetails(headings, pageRedirects); | ||
|
||
return { | ||
score: UnusedBytes.scoreForWastedMs(totalWastedMs), | ||
// We award a passing grade if you only have 1 redirect | ||
score: redirectRequests.length === 2 ? 100 : UnusedBytes.scoreForWastedMs(totalWastedMs), |
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.
could we add a passing test case for a resource with 0 redirects too? I had to pause for a second on this, alternatively switch to redirectRequests.length <= 2
Changes:
screenshots
failing with 2 redirects:
passing with 1 redirect:
passing with 0 redirects: