Skip to content
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

core: warn if document was redirected #10157

Merged
merged 5 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const expectations = [
},
},
},
runWarnings: [
/The page may not be loading as expected because your test URL \(.*online-only.html.*\) was redirected to .*redirects-final.html. Try testing the second URL directly./,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a non-deterministic component of this that warrants a regex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this first one - yes, cacheBuster is a new Date. The second - no. Still good for eliding the URL query params that don't matter.

],
},
},
{
Expand All @@ -44,6 +47,9 @@ const expectations = [
},
},
},
runWarnings: [
/The page may not be loading as expected because your test URL \(.*online-only.html.*\) was redirected to .*redirects-final.html. Try testing the second URL directly./,
],
},
},
];
Expand Down
20 changes: 20 additions & 0 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ const NetworkRecorder = require('../lib/network-recorder.js');
const constants = require('../config/constants.js');
const i18n = require('../lib/i18n/i18n.js');

const UIStrings = {
/**
* @description Warning that the web page redirected during testing and that may have affected the load.
* @example {https://example.com/requested/page} requested
* @example {https://example.com/final/resolved/page} final
*/
warningRedirected: 'The page may not be loading as expected because your test URL ' +
`({requested}) was redirected to {final}. ` +
'Try testing the second URL directly.',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);

/** @typedef {import('../gather/driver.js')} Driver */

/** @typedef {import('./gatherers/gatherer.js').PhaseResult} PhaseResult */
Expand Down Expand Up @@ -491,6 +504,12 @@ class GatherRunner {

// Copy redirected URL to artifact.
baseArtifacts.URL.finalUrl = passContext.url;
if (baseArtifacts.URL.requestedUrl !== baseArtifacts.URL.finalUrl) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably use equal without fragments?

baseArtifacts.LighthouseRunWarnings.push(str_(UIStrings.warningRedirected, {
requested: baseArtifacts.URL.requestedUrl,
final: baseArtifacts.URL.finalUrl,
}));
}

// Fetch the manifest, if it exists.
baseArtifacts.WebAppManifest = await GatherRunner.getWebAppManifest(passContext);
Expand Down Expand Up @@ -672,3 +691,4 @@ class GatherRunner {
}

module.exports = GatherRunner;
module.exports.UIStrings = UIStrings;
3 changes: 3 additions & 0 deletions lighthouse-core/lib/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,9 @@
"lighthouse-core/config/default-config.js | seoMobileGroupTitle": {
"message": "Mobile Friendly"
},
"lighthouse-core/gather/gather-runner.js | warningRedirected": {
"message": "The page may not be loading as expected because your test URL ({requested}) was redirected to {final}. Try testing the second URL directly."
},
"lighthouse-core/lib/i18n/i18n.js | columnCacheTTL": {
"message": "Cache TTL"
},
Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/lib/i18n/locales/en-XL.json
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,9 @@
"lighthouse-core/config/default-config.js | seoMobileGroupTitle": {
"message": "M̂ób̂íl̂é F̂ŕîén̂d́l̂ý"
},
"lighthouse-core/gather/gather-runner.js | warningRedirected": {
"message": "T̂h́ê ṕâǵê ḿâý n̂ót̂ b́ê ĺôád̂ín̂ǵ âś êx́p̂éĉt́êd́ b̂éĉáûśê ýôúr̂ t́êśt̂ ÚR̂Ĺ ({requested}) ŵáŝ ŕêd́îŕêćt̂éd̂ t́ô {final}. T́r̂ý t̂éŝt́îńĝ t́ĥé ŝéĉón̂d́ ÛŔL̂ d́îŕêćt̂ĺŷ."
},
"lighthouse-core/lib/i18n/i18n.js | columnCacheTTL": {
"message": "Ĉáĉh́ê T́T̂Ĺ"
},
Expand Down
2 changes: 1 addition & 1 deletion types/smokehouse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
audits: Record<string, any>;
requestedUrl: string;
finalUrl: string;
runWarnings?: Array<string>;
runWarnings?: Array<string|RegExp>;
runtimeError?: {
code?: any;
message?: any;
Expand Down