diff --git a/lighthouse-cli/test/fixtures/redirects-self.html b/lighthouse-cli/test/fixtures/redirects-self.html new file mode 100644 index 000000000000..33db793aba33 --- /dev/null +++ b/lighthouse-cli/test/fixtures/redirects-self.html @@ -0,0 +1,23 @@ + + + + + + + + +

Redirect to myself

+ + + diff --git a/lighthouse-cli/test/smokehouse/core-tests.js b/lighthouse-cli/test/smokehouse/core-tests.js index baa0ae672205..23cfbd390b58 100644 --- a/lighthouse-cli/test/smokehouse/core-tests.js +++ b/lighthouse-cli/test/smokehouse/core-tests.js @@ -53,6 +53,7 @@ import redirectsHistoryPushState from './test-definitions/redirects-history-push import redirectsMultipleServer from './test-definitions/redirects-multiple-server.js'; import redirectsSingleClient from './test-definitions/redirects-single-client.js'; import redirectsSingleServer from './test-definitions/redirects-single-server.js'; +import redirectsSelf from './test-definitions/redirects-self.js'; import screenshot from './test-definitions/screenshot.js'; import seoFailing from './test-definitions/seo-failing.js'; import seoPassing from './test-definitions/seo-passing.js'; @@ -111,6 +112,7 @@ const smokeTests = [ redirectsMultipleServer, redirectsSingleClient, redirectsSingleServer, + redirectsSelf, screenshot, seoFailing, seoPassing, diff --git a/lighthouse-cli/test/smokehouse/test-definitions/redirects-self.js b/lighthouse-cli/test/smokehouse/test-definitions/redirects-self.js new file mode 100644 index 000000000000..2de7936fe8eb --- /dev/null +++ b/lighthouse-cli/test/smokehouse/test-definitions/redirects-self.js @@ -0,0 +1,30 @@ +/** + * @license Copyright 2022 The Lighthouse Authors. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +/** + * @type {Smokehouse.ExpectedRunnerResult} + */ +const expectations = { + artifacts: { + MainDocumentContent: /Redirect to myself/, + }, + lhr: { + requestedUrl: 'http://localhost:10200/redirects-self.html', + finalUrl: 'http://localhost:10200/redirects-self.html?done=', + audits: { + }, + runWarnings: [ + 'The page may not be loading as expected because your test URL (http://localhost:10200/redirects-self.html) was redirected to http://localhost:10200/redirects-self.html?done=. Try testing the second URL directly.', + ], + }, +}; + +export default { + id: 'redirects-self', + expectations, +}; + diff --git a/lighthouse-core/fraggle-rock/gather/navigation-runner.js b/lighthouse-core/fraggle-rock/gather/navigation-runner.js index 78d751fec6fe..9f1d32e1ab41 100644 --- a/lighthouse-core/fraggle-rock/gather/navigation-runner.js +++ b/lighthouse-core/fraggle-rock/gather/navigation-runner.js @@ -210,6 +210,7 @@ async function _computeNavigationResult( async function _navigation(navigationContext) { const artifactState = getEmptyArtifactState(); const phaseState = { + url: await navigationContext.driver.url(), gatherMode: /** @type {const} */ ('navigation'), driver: navigationContext.driver, computedCache: navigationContext.computedCache, @@ -223,6 +224,7 @@ async function _navigation(navigationContext) { await collectPhaseArtifacts({phase: 'startInstrumentation', ...phaseState}); await collectPhaseArtifacts({phase: 'startSensitiveInstrumentation', ...phaseState}); const navigateResult = await _navigate(navigationContext); + phaseState.url = navigateResult.finalUrl; await collectPhaseArtifacts({phase: 'stopSensitiveInstrumentation', ...phaseState}); await collectPhaseArtifacts({phase: 'stopInstrumentation', ...phaseState}); await _cleanupNavigation(navigationContext); diff --git a/lighthouse-core/fraggle-rock/gather/runner-helpers.js b/lighthouse-core/fraggle-rock/gather/runner-helpers.js index 4521e2832839..903d4dda6de8 100644 --- a/lighthouse-core/fraggle-rock/gather/runner-helpers.js +++ b/lighthouse-core/fraggle-rock/gather/runner-helpers.js @@ -15,6 +15,7 @@ * @property {LH.Gatherer.GatherMode} gatherMode * @property {Map} computedCache * @property {LH.Config.Settings} settings + * @property {string} url */ /** @typedef {Record>} IntermediateArtifacts */ @@ -74,6 +75,7 @@ async function collectPhaseArtifacts(options) { gatherMode, computedCache, settings, + url, } = options; const priorPhase = phaseToPriorPhase[phase]; const priorPhaseArtifacts = (priorPhase && artifactState[priorPhase]) || {}; @@ -90,7 +92,7 @@ async function collectPhaseArtifacts(options) { : /** @type {Dependencies} */ ({}); return gatherer[phase]({ - url: await driver.url(), + url, gatherMode, driver, baseArtifacts, diff --git a/lighthouse-core/fraggle-rock/gather/snapshot-runner.js b/lighthouse-core/fraggle-rock/gather/snapshot-runner.js index ba2c87c27814..8962dce3cd64 100644 --- a/lighthouse-core/fraggle-rock/gather/snapshot-runner.js +++ b/lighthouse-core/fraggle-rock/gather/snapshot-runner.js @@ -27,7 +27,7 @@ async function snapshot(options) { /** @type {Map} */ const computedCache = new Map(); - const url = await options.page.url(); + const url = await driver.url(); const runnerOptions = {config, computedCache}; const artifacts = await Runner.gather( @@ -39,6 +39,7 @@ async function snapshot(options) { const artifactDefinitions = config.artifacts || []; const artifactState = getEmptyArtifactState(); await collectPhaseArtifacts({ + url, phase: 'getArtifact', gatherMode: 'snapshot', driver, diff --git a/lighthouse-core/fraggle-rock/gather/timespan-runner.js b/lighthouse-core/fraggle-rock/gather/timespan-runner.js index 27b85be4b708..66ee6ac419db 100644 --- a/lighthouse-core/fraggle-rock/gather/timespan-runner.js +++ b/lighthouse-core/fraggle-rock/gather/timespan-runner.js @@ -32,11 +32,12 @@ async function startTimespan(options) { /** @type {Map} */ const computedCache = new Map(); const artifactDefinitions = config.artifacts || []; - const requestedUrl = await options.page.url(); + const requestedUrl = await driver.url(); const baseArtifacts = await getBaseArtifacts(config, driver, {gatherMode: 'timespan'}); const artifactState = getEmptyArtifactState(); /** @type {Omit} */ const phaseOptions = { + url: requestedUrl, driver, artifactDefinitions, artifactState, @@ -52,7 +53,9 @@ async function startTimespan(options) { return { async endTimespan() { - const finalUrl = await options.page.url(); + const finalUrl = await driver.url(); + phaseOptions.url = finalUrl; + const runnerOptions = {config, computedCache}; const artifacts = await Runner.gather( async () => { diff --git a/lighthouse-core/test/fraggle-rock/gather/mock-driver.js b/lighthouse-core/test/fraggle-rock/gather/mock-driver.js index 0dbb11c1bc06..8570d1ccb7e5 100644 --- a/lighthouse-core/test/fraggle-rock/gather/mock-driver.js +++ b/lighthouse-core/test/fraggle-rock/gather/mock-driver.js @@ -129,7 +129,7 @@ function createMockDriver() { _page: page, _executionContext: context, _session: session, - url: () => page.url(), + url: jest.fn(() => page.url()), defaultSession: session, connect: jest.fn(), disconnect: jest.fn(), diff --git a/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js b/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js index cd17908c3d2e..4376dda1dc35 100644 --- a/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js +++ b/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js @@ -132,6 +132,7 @@ describe('collectPhaseArtifacts', () => { it(`should run the ${phase} phase of gatherers in ${gatherMode} mode`, async () => { const {artifactDefinitions, gatherers} = createGathererSet(); await helpers.collectPhaseArtifacts({ + url: 'https://example.com', driver, artifactDefinitions, artifactState, @@ -156,6 +157,7 @@ describe('collectPhaseArtifacts', () => { it('should gather the artifacts', async () => { const {artifactDefinitions} = createGathererSet(); await helpers.collectPhaseArtifacts({ + url: 'https://example.com', driver, artifactDefinitions, artifactState, @@ -188,6 +190,7 @@ describe('collectPhaseArtifacts', () => { ]; await helpers.collectPhaseArtifacts({ + url: 'https://example.com', driver, artifactDefinitions, artifactState, @@ -221,6 +224,7 @@ describe('collectPhaseArtifacts', () => { const {artifactDefinitions, gatherers} = createGathererSet(); await helpers.collectPhaseArtifacts({ + url: 'https://example.com', driver, artifactDefinitions, artifactState, diff --git a/lighthouse-core/test/fraggle-rock/gather/snapshot-runner-test.js b/lighthouse-core/test/fraggle-rock/gather/snapshot-runner-test.js index b74c11572148..39125dee3e72 100644 --- a/lighthouse-core/test/fraggle-rock/gather/snapshot-runner-test.js +++ b/lighthouse-core/test/fraggle-rock/gather/snapshot-runner-test.js @@ -71,7 +71,7 @@ describe('Snapshot Runner', () => { }); it('should collect base artifacts', async () => { - mockPage.url.mockResolvedValue('https://lighthouse.example.com/'); + mockDriver.url.mockResolvedValue('https://lighthouse.example.com/'); await snapshot({page, config}); const artifacts = await mockRunner.gather.mock.calls[0][0](); diff --git a/lighthouse-core/test/fraggle-rock/gather/timespan-runner-test.js b/lighthouse-core/test/fraggle-rock/gather/timespan-runner-test.js index d89b9d4184ad..48f866d3d957 100644 --- a/lighthouse-core/test/fraggle-rock/gather/timespan-runner-test.js +++ b/lighthouse-core/test/fraggle-rock/gather/timespan-runner-test.js @@ -90,11 +90,11 @@ describe('Timespan Runner', () => { }); it('should collect base artifacts', async () => { - mockPage.url.mockResolvedValue('https://start.example.com/'); + mockDriver.url.mockResolvedValue('https://start.example.com/'); const timespan = await startTimespan({page, config}); - mockPage.url.mockResolvedValue('https://end.example.com/'); + mockDriver.url.mockResolvedValue('https://end.example.com/'); await timespan.endTimespan(); const artifacts = await mockRunner.gather.mock.calls[0][0]();