diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js index 85616240be77..230a70d0d506 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js @@ -89,7 +89,7 @@ module.exports = [ { lhr: { - requestedUrl: 'https://www.chromestatus.com/', + requestedUrl: 'https://www.chromestatus.com/features', finalUrl: 'https://www.chromestatus.com/features', audits: { 'is-on-https': { @@ -102,7 +102,7 @@ module.exports = [ score: 1, }, 'works-offline': { - score: 0, + score: 1, }, 'offline-start-url': { score: 1, diff --git a/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js index 06b66ac63746..68a37e3b3156 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js @@ -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./, + ], }, }, { @@ -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./, + ], }, }, ]; diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 8e094289a9fe..09694b9b7601 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -13,6 +13,20 @@ const NetworkAnalyzer = require('../lib/dependency-graph/simulator/network-analy const NetworkRecorder = require('../lib/network-recorder.js'); const constants = require('../config/constants.js'); const i18n = require('../lib/i18n/i18n.js'); +const URL = require('../lib/url-shim.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 */ @@ -491,6 +505,13 @@ class GatherRunner { // Copy redirected URL to artifact. baseArtifacts.URL.finalUrl = passContext.url; + /* eslint-disable max-len */ + if (!URL.equalWithExcludedFragments(baseArtifacts.URL.requestedUrl, baseArtifacts.URL.finalUrl)) { + 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); @@ -672,3 +693,4 @@ class GatherRunner { } module.exports = GatherRunner; +module.exports.UIStrings = UIStrings; diff --git a/lighthouse-core/lib/i18n/locales/en-US.json b/lighthouse-core/lib/i18n/locales/en-US.json index 8aca1302f53b..e9ce7b02e1ba 100644 --- a/lighthouse-core/lib/i18n/locales/en-US.json +++ b/lighthouse-core/lib/i18n/locales/en-US.json @@ -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" }, diff --git a/lighthouse-core/lib/i18n/locales/en-XL.json b/lighthouse-core/lib/i18n/locales/en-XL.json index 3daf14887193..816bd7837bb4 100644 --- a/lighthouse-core/lib/i18n/locales/en-XL.json +++ b/lighthouse-core/lib/i18n/locales/en-XL.json @@ -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̂Ĺ" }, diff --git a/lighthouse-core/test/gather/fake-driver.js b/lighthouse-core/test/gather/fake-driver.js index 108a40aa6d78..fe5fa8ba97fb 100644 --- a/lighthouse-core/test/gather/fake-driver.js +++ b/lighthouse-core/test/gather/fake-driver.js @@ -24,8 +24,9 @@ function makeFakeDriver({protocolGetVersionResponse}) { disconnect() { return Promise.resolve(); }, - gotoURL() { - return Promise.resolve('https://www.reddit.com/r/nba'); + /** @param {string} url */ + gotoURL(url) { + return Promise.resolve(url); }, beginEmulation() { return Promise.resolve(); diff --git a/types/smokehouse.d.ts b/types/smokehouse.d.ts index 070015b1fccc..caa4e7746e5b 100644 --- a/types/smokehouse.d.ts +++ b/types/smokehouse.d.ts @@ -9,7 +9,7 @@ audits: Record; requestedUrl: string; finalUrl: string; - runWarnings?: Array; + runWarnings?: Array; runtimeError?: { code?: any; message?: any;