report(redirects): reformat results, incl all requests and wasted time,#3492
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.
This >1 and a === 2 below could instead use a ACCEPTED_REDIRECTS const if folks prefer.
| const FAILING_REDIRECTS = { | ||
| const FAILING_THREE_REDIRECTS = { | ||
| startTime: 17, | ||
| url: 'http://exampel.com/', |
There was a problem hiding this comment.
this was deliberate. :)
wardpeet
left a comment
There was a problem hiding this comment.
Looks good, thanks for cleaning up! Really appreciate it! 🥇
Just a few remarks about urls and spelling 😄
|
|
||
| const FAILING_TWO_REDIRECTS = { | ||
| startTime: 446.286, | ||
| url: 'http://lisairish.com/', |
There was a problem hiding this comment.
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.
Well i tested this with these actual URLs, which have this set of redirects setup.
lighthouse-core/audits/redirects.js
Outdated
| 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.
if totalWastedMs === 0 scoreForWastedMs doesn't already give you a 100?
There was a problem hiding this comment.
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.
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.
already have passing test case for 0 redirects.
changed to <= 2.
brendankenny
left a comment
There was a problem hiding this comment.
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.
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)
|
updated! @brendankenny ptal. |
|
will you rebase to pick up the passive event listener fix? |
714bbad to
0b032a9
Compare
|
@brendankenny thar u go |
brendankenny
left a comment
There was a problem hiding this comment.
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); | ||
| }); | ||
| }); |
lighthouse-core/audits/redirects.js
Outdated
| 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.
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:
