diff --git a/lighthouse-cli/test/smokehouse/test-definitions/seo/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/seo/expectations.js index d4bec07c7f24..101764914fe2 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/seo/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/seo/expectations.js @@ -343,6 +343,7 @@ const status403 = { // Note: most scores are null (audit error) because the page 403ed. requestedUrl: BASE_URL + 'seo-failure-cases.html?status_code=403', finalUrl: BASE_URL + 'seo-failure-cases.html?status_code=403', + userAgent: /Chrom(e|ium)/, // Ensure we still collect base artifacts when page fails to load. runtimeError: { code: 'ERRORED_DOCUMENT_REQUEST', message: /Status code: 403/, diff --git a/lighthouse-core/fraggle-rock/config/default-config.js b/lighthouse-core/fraggle-rock/config/default-config.js index 094c0090906d..1ea71da6b238 100644 --- a/lighthouse-core/fraggle-rock/config/default-config.js +++ b/lighthouse-core/fraggle-rock/config/default-config.js @@ -49,8 +49,6 @@ const artifacts = { FullPageScreenshot: '', GatherContext: '', GlobalListeners: '', - HostFormFactor: '', - HostUserAgent: '', IFrameElements: '', ImageElements: '', InstallabilityErrors: '', @@ -85,8 +83,6 @@ for (const key of Object.keys(artifacts)) { const defaultConfig = { artifacts: [ // Artifacts which can be depended on come first. - {id: artifacts.HostUserAgent, gatherer: 'host-user-agent'}, - {id: artifacts.HostFormFactor, gatherer: 'host-form-factor'}, {id: artifacts.DevtoolsLog, gatherer: 'devtools-log'}, {id: artifacts.Trace, gatherer: 'trace'}, @@ -142,8 +138,6 @@ const defaultConfig = { cpuQuietThresholdMs: 1000, artifacts: [ // Artifacts which can be depended on come first. - artifacts.HostUserAgent, - artifacts.HostFormFactor, artifacts.DevtoolsLog, artifacts.Trace, diff --git a/lighthouse-core/fraggle-rock/config/filters.js b/lighthouse-core/fraggle-rock/config/filters.js index 657b590eaf9a..4520c7ec293d 100644 --- a/lighthouse-core/fraggle-rock/config/filters.js +++ b/lighthouse-core/fraggle-rock/config/filters.js @@ -16,6 +16,8 @@ const baseArtifactKeySource = { Timing: '', URL: '', PageLoadError: '', + HostFormFactor: '', + HostUserAgent: '', }; const baseArtifactKeys = Object.keys(baseArtifactKeySource); diff --git a/lighthouse-core/fraggle-rock/gather/base-artifacts.js b/lighthouse-core/fraggle-rock/gather/base-artifacts.js index c58385d0ce27..efb5e6ce72d8 100644 --- a/lighthouse-core/fraggle-rock/gather/base-artifacts.js +++ b/lighthouse-core/fraggle-rock/gather/base-artifacts.js @@ -8,6 +8,7 @@ const log = require('lighthouse-logger'); const isEqual = require('lodash.isequal'); const { + getBrowserVersion, getBenchmarkIndex, getEnvironmentWarnings, } = require('../../gather/driver/environment.js'); @@ -19,6 +20,7 @@ const { */ async function getBaseArtifacts(config, driver) { const BenchmarkIndex = await getBenchmarkIndex(driver.executionContext); + const {userAgent} = await getBrowserVersion(driver.defaultSession); return { // Meta artifacts. @@ -28,12 +30,13 @@ async function getBaseArtifacts(config, driver) { settings: config.settings, // Environment artifacts that can always be computed. BenchmarkIndex, + HostUserAgent: userAgent, + HostFormFactor: userAgent.includes('Android') || userAgent.includes('Mobile') ? + 'mobile' : 'desktop', // Contextual artifacts whose collection changes based on gather mode. URL: {requestedUrl: '', finalUrl: ''}, PageLoadError: null, // Artifacts that have been replaced by regular gatherers in Fraggle Rock. - HostFormFactor: 'mobile', - HostUserAgent: '', Stacks: [], NetworkUserAgent: '', WebAppManifest: null, diff --git a/lighthouse-core/fraggle-rock/gather/navigation-runner.js b/lighthouse-core/fraggle-rock/gather/navigation-runner.js index ab5f4bbc33e7..34251815c1e0 100644 --- a/lighthouse-core/fraggle-rock/gather/navigation-runner.js +++ b/lighthouse-core/fraggle-rock/gather/navigation-runner.js @@ -32,6 +32,7 @@ const NetworkRecords = require('../../computed/network-records.js'); * @property {LH.Config.FRConfig} config * @property {LH.Config.NavigationDefn} navigation * @property {string} requestedUrl + * @property {LH.FRBaseArtifacts} baseArtifacts * @property {Map} computedCache */ @@ -182,6 +183,7 @@ async function _navigation(navigationContext) { computedCache: navigationContext.computedCache, artifactDefinitions: navigationContext.navigation.artifacts, artifactState, + baseArtifacts: navigationContext.baseArtifacts, settings: navigationContext.config.settings, }; @@ -197,10 +199,10 @@ async function _navigation(navigationContext) { } /** - * @param {{driver: Driver, config: LH.Config.FRConfig, requestedUrl: string; computedCache: NavigationContext['computedCache']}} args + * @param {{driver: Driver, config: LH.Config.FRConfig, requestedUrl: string; baseArtifacts: LH.FRBaseArtifacts, computedCache: NavigationContext['computedCache']}} args * @return {Promise<{artifacts: Partial}>} */ -async function _navigations({driver, config, requestedUrl, computedCache}) { +async function _navigations({driver, config, requestedUrl, baseArtifacts, computedCache}) { if (!config.navigations) throw new Error('No navigations configured'); /** @type {Partial} */ @@ -214,6 +216,7 @@ async function _navigations({driver, config, requestedUrl, computedCache}) { navigation, requestedUrl, config, + baseArtifacts, computedCache, }; @@ -258,9 +261,10 @@ async function navigation(options) { return Runner.run( async () => { const driver = new Driver(page); - const {baseArtifacts} = await _setup({driver, config, requestedUrl}); - const {artifacts} = await _navigations({driver, config, requestedUrl, computedCache}); - await _cleanup({driver, config, requestedUrl}); + const context = {driver, config, requestedUrl}; + const {baseArtifacts} = await _setup(context); + const {artifacts} = await _navigations({...context, baseArtifacts, computedCache}); + await _cleanup(context); return finalizeArtifacts(baseArtifacts, artifacts); }, diff --git a/lighthouse-core/fraggle-rock/gather/runner-helpers.js b/lighthouse-core/fraggle-rock/gather/runner-helpers.js index b4ddc01a69d7..4521e2832839 100644 --- a/lighthouse-core/fraggle-rock/gather/runner-helpers.js +++ b/lighthouse-core/fraggle-rock/gather/runner-helpers.js @@ -10,6 +10,7 @@ * @property {import('./driver.js')} driver * @property {Array} artifactDefinitions * @property {ArtifactState} artifactState + * @property {LH.FRBaseArtifacts} baseArtifacts * @property {LH.Gatherer.FRGatherPhase} phase * @property {LH.Gatherer.GatherMode} gatherMode * @property {Map} computedCache @@ -68,6 +69,7 @@ async function collectPhaseArtifacts(options) { driver, artifactDefinitions, artifactState, + baseArtifacts, phase, gatherMode, computedCache, @@ -91,6 +93,7 @@ async function collectPhaseArtifacts(options) { url: await driver.url(), gatherMode, driver, + baseArtifacts, dependencies, computedCache, settings, diff --git a/lighthouse-core/fraggle-rock/gather/snapshot-runner.js b/lighthouse-core/fraggle-rock/gather/snapshot-runner.js index 35c3916aeeec..f024120d8beb 100644 --- a/lighthouse-core/fraggle-rock/gather/snapshot-runner.js +++ b/lighthouse-core/fraggle-rock/gather/snapshot-runner.js @@ -38,6 +38,7 @@ async function snapshot(options) { phase: 'getArtifact', gatherMode: 'snapshot', driver, + baseArtifacts, artifactDefinitions, artifactState, computedCache, diff --git a/lighthouse-core/fraggle-rock/gather/timespan-runner.js b/lighthouse-core/fraggle-rock/gather/timespan-runner.js index 2983aabf2c63..38374d5ae488 100644 --- a/lighthouse-core/fraggle-rock/gather/timespan-runner.js +++ b/lighthouse-core/fraggle-rock/gather/timespan-runner.js @@ -29,12 +29,14 @@ async function startTimespan(options) { const computedCache = new Map(); const artifactDefinitions = config.artifacts || []; const requestedUrl = await options.page.url(); + const baseArtifacts = await getBaseArtifacts(config, driver); const artifactState = getEmptyArtifactState(); /** @type {Omit} */ const phaseOptions = { driver, artifactDefinitions, artifactState, + baseArtifacts, computedCache, gatherMode: 'timespan', settings: config.settings, @@ -48,7 +50,6 @@ async function startTimespan(options) { const finalUrl = await options.page.url(); return Runner.run( async () => { - const baseArtifacts = await getBaseArtifacts(config, driver); baseArtifacts.URL.requestedUrl = requestedUrl; baseArtifacts.URL.finalUrl = finalUrl; diff --git a/lighthouse-core/gather/gatherers/host-form-factor.js b/lighthouse-core/gather/gatherers/host-form-factor.js deleted file mode 100644 index 5b7d1bf51d5c..000000000000 --- a/lighthouse-core/gather/gatherers/host-form-factor.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @license Copyright 2021 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'; - -const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js'); -const HostUserAgent = require('./host-user-agent.js'); - -class HostFormFactor extends FRGatherer { - static symbol = Symbol('HostFormFactor'); - - /** @type {LH.Gatherer.GathererMeta<'HostUserAgent'>} */ - meta = { - symbol: HostFormFactor.symbol, - supportedModes: ['snapshot', 'timespan', 'navigation'], - dependencies: {HostUserAgent: HostUserAgent.symbol}, - }; - - /** - * @param {LH.Gatherer.FRTransitionalContext<'HostUserAgent'>} context - * @return {Promise} - */ - async getArtifact(context) { - const userAgent = context.dependencies.HostUserAgent; - return userAgent.includes('Android') || userAgent.includes('Mobile') ? 'mobile' : 'desktop'; - } -} - -module.exports = HostFormFactor; diff --git a/lighthouse-core/gather/gatherers/host-user-agent.js b/lighthouse-core/gather/gatherers/host-user-agent.js deleted file mode 100644 index f49d1cb5cf27..000000000000 --- a/lighthouse-core/gather/gatherers/host-user-agent.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @license Copyright 2021 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'; - -const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js'); -const {getBrowserVersion} = require('../driver/environment.js'); - -class HostUserAgent extends FRGatherer { - static symbol = Symbol('HostUserAgent'); - - /** @type {LH.Gatherer.GathererMeta} */ - meta = { - symbol: HostUserAgent.symbol, - supportedModes: ['snapshot', 'timespan', 'navigation'], - }; - - /** - * @param {LH.Gatherer.FRTransitionalContext} context - * @return {Promise} - */ - getArtifact(context) { - return getBrowserVersion(context.driver.defaultSession).then(v => v.userAgent); - } -} - -module.exports = HostUserAgent; diff --git a/lighthouse-core/gather/gatherers/script-elements.js b/lighthouse-core/gather/gatherers/script-elements.js index fda2d6a6590d..a3db95418c67 100644 --- a/lighthouse-core/gather/gatherers/script-elements.js +++ b/lighthouse-core/gather/gatherers/script-elements.js @@ -12,7 +12,6 @@ const NetworkRequest = require('../../lib/network-request.js'); const pageFunctions = require('../../lib/page-functions.js'); const {fetchResponseBodyFromCache} = require('../driver/network.js'); const DevtoolsLog = require('./devtools-log.js'); -const HostFormFactor = require('./host-form-factor.js'); /* global getNodeDetails */ @@ -67,10 +66,10 @@ async function runInSeriesOrParallel(values, promiseMapper, runInSeries) { * @fileoverview Gets JavaScript file contents. */ class ScriptElements extends FRGatherer { - /** @type {LH.Gatherer.GathererMeta<'DevtoolsLog'|'HostFormFactor'>} */ + /** @type {LH.Gatherer.GathererMeta<'DevtoolsLog'>} */ meta = { supportedModes: ['timespan', 'navigation'], - dependencies: {DevtoolsLog: DevtoolsLog.symbol, HostFormFactor: HostFormFactor.symbol}, + dependencies: {DevtoolsLog: DevtoolsLog.symbol}, } /** @@ -138,11 +137,11 @@ class ScriptElements extends FRGatherer { } /** - * @param {LH.Gatherer.FRTransitionalContext<'DevtoolsLog'|'HostFormFactor'>} context + * @param {LH.Gatherer.FRTransitionalContext<'DevtoolsLog'>} context */ async getArtifact(context) { const devtoolsLog = context.dependencies.DevtoolsLog; - const formFactor = context.dependencies.HostFormFactor; + const formFactor = context.baseArtifacts.HostFormFactor; const networkRecords = await NetworkRecords.request(devtoolsLog, context); return this._getArtifact(context, networkRecords, formFactor); } diff --git a/lighthouse-core/test/fraggle-rock/api-test-pptr.js b/lighthouse-core/test/fraggle-rock/api-test-pptr.js index f0bbe8bf10f2..a92ca7edf26e 100644 --- a/lighthouse-core/test/fraggle-rock/api-test-pptr.js +++ b/lighthouse-core/test/fraggle-rock/api-test-pptr.js @@ -14,6 +14,14 @@ const StaticServer = require('../../../lighthouse-cli/test/fixtures/static-serve jest.setTimeout(90_000); +/** + * Some audits can be notApplicable based on machine timing information. + * Exclude these audits from applicability comparisons. */ +const FLAKY_AUDIT_IDS_APPLICABILITY = new Set([ + 'long-tasks', + 'screenshot-thumbnails', +]); + /** * @param {LH.Result} lhr */ @@ -25,7 +33,10 @@ function getAuditsBreakdown(lhr) { ); const notApplicableAudits = auditResults.filter( - audit => audit.scoreDisplayMode === 'notApplicable' + audit => ( + audit.scoreDisplayMode === 'notApplicable' && + !FLAKY_AUDIT_IDS_APPLICABILITY.has(audit.id) + ) ); const informativeAudits = applicableAudits.filter( @@ -38,7 +49,7 @@ function getAuditsBreakdown(lhr) { const failedAudits = applicableAudits.filter(audit => audit.score !== null && audit.score < 1); - return {auditResults, erroredAudits, failedAudits, informativeAudits, notApplicableAudits}; + return {auditResults, erroredAudits, failedAudits, notApplicableAudits}; } describe('Fraggle Rock API', () => { diff --git a/lighthouse-core/test/fraggle-rock/gather/base-artifacts-test.js b/lighthouse-core/test/fraggle-rock/gather/base-artifacts-test.js index bab86f6da2f1..b83552ef95e0 100644 --- a/lighthouse-core/test/fraggle-rock/gather/base-artifacts-test.js +++ b/lighthouse-core/test/fraggle-rock/gather/base-artifacts-test.js @@ -18,6 +18,10 @@ const LighthouseError = require('../../../lib/lh-error.js'); function getMockDriverForArtifacts() { const driverMock = createMockDriver(); driverMock._executionContext.evaluate.mockResolvedValue(500); + driverMock._session.sendCommand.mockResponse('Browser.getVersion', { + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36', // eslint-disable-line max-len + product: 'Chrome/92.0.4515.159', + }); return driverMock; } @@ -34,6 +38,13 @@ describe('getBaseArtifacts', () => { expect(artifacts.BenchmarkIndex).toEqual(500); }); + it('should fetch host user agent', async () => { + const {config} = initializeConfig(undefined, {gatherMode: 'navigation'}); + const artifacts = await getBaseArtifacts(config, driverMock.asDriver()); + expect(artifacts.HostUserAgent).toContain('Macintosh'); + expect(artifacts.HostFormFactor).toEqual('desktop'); + }); + it('should return settings', async () => { const {config} = initializeConfig(undefined, {gatherMode: 'navigation'}); const artifacts = await getBaseArtifacts(config, driverMock.asDriver()); diff --git a/lighthouse-core/test/fraggle-rock/gather/mock-driver.js b/lighthouse-core/test/fraggle-rock/gather/mock-driver.js index 38366d9e61b6..3f185a9cd795 100644 --- a/lighthouse-core/test/fraggle-rock/gather/mock-driver.js +++ b/lighthouse-core/test/fraggle-rock/gather/mock-driver.js @@ -159,6 +159,23 @@ function mockDriverModule(driverProvider) { }; } +/** + * @returns {LH.FRBaseArtifacts} + */ +function createMockBaseArtifacts() { + return { + fetchTime: new Date().toISOString(), + URL: {finalUrl: 'https://example.com', requestedUrl: 'https://example.com'}, + PageLoadError: null, + settings: defaultSettings, + BenchmarkIndex: 500, + LighthouseRunWarnings: [], + Timing: [], + HostFormFactor: 'desktop', + HostUserAgent: 'Chrome/93.0.1449.0', + }; +} + function mockTargetManagerModule() { const targetManagerMock = createMockTargetManager(); @@ -180,6 +197,7 @@ function createMockContext() { gatherMode: 'navigation', computedCache: new Map(), dependencies: {}, + baseArtifacts: createMockBaseArtifacts(), settings: defaultSettings, /** @return {LH.Gatherer.FRTransitionalContext} */ @@ -260,5 +278,6 @@ module.exports = { createMockPage, createMockSession, createMockGathererInstance, + createMockBaseArtifacts, createMockContext, }; diff --git a/lighthouse-core/test/fraggle-rock/gather/navigation-runner-test.js b/lighthouse-core/test/fraggle-rock/gather/navigation-runner-test.js index e17b4ce05bd2..d7b05faa8bab 100644 --- a/lighthouse-core/test/fraggle-rock/gather/navigation-runner-test.js +++ b/lighthouse-core/test/fraggle-rock/gather/navigation-runner-test.js @@ -7,7 +7,12 @@ /* eslint-env jest */ -const {createMockDriver, mockDriverSubmodules, mockRunnerModule} = require('./mock-driver.js'); +const { + createMockDriver, + createMockBaseArtifacts, + mockDriverSubmodules, + mockRunnerModule, +} = require('./mock-driver.js'); const mocks = mockDriverSubmodules(); const {initializeConfig} = require('../../../fraggle-rock/config/config.js'); const {defaultNavigationConfig} = require('../../../config/constants.js'); @@ -36,6 +41,8 @@ describe('NavigationRunner', () => { let navigation; /** @type {Map} */ let computedCache; + /** @type {LH.FRBaseArtifacts} */ + let baseArtifacts; /** @return {LH.Config.AnyFRGathererDefn} */ function createGathererDefn() { @@ -89,6 +96,7 @@ describe('NavigationRunner', () => { config = initializeConfig(undefined, {gatherMode: 'navigation'}).config; navigation = createNavigation().navigation; computedCache = new Map(); + baseArtifacts = createMockBaseArtifacts(); mockDriver = createMockDriver(); driver = mockDriver.asDriver(); @@ -139,7 +147,8 @@ describe('NavigationRunner', () => { }); describe('_navigations', () => { - const run = () => runner._navigations({driver, config, requestedUrl, computedCache}); + const run = () => + runner._navigations({driver, config, requestedUrl, computedCache, baseArtifacts}); it('should throw if no navigations available', async () => { config = {...config, navigations: null}; @@ -223,7 +232,7 @@ describe('NavigationRunner', () => { describe('_navigation', () => { /** @param {LH.Config.NavigationDefn} navigation */ const run = navigation => - runner._navigation({driver, config, navigation, requestedUrl, computedCache}); + runner._navigation({driver, config, navigation, requestedUrl, computedCache, baseArtifacts}); it('completes an end-to-end navigation', async () => { const {artifacts} = await run(navigation); @@ -353,7 +362,14 @@ describe('NavigationRunner', () => { describe('_setupNavigation', () => { it('should setup the page on the blankPage', async () => { navigation.blankPage = 'data:text/html;...'; - await runner._setupNavigation({driver, navigation, requestedUrl, config, computedCache}); + await runner._setupNavigation({ + driver, + navigation, + requestedUrl, + config, + computedCache, + baseArtifacts, + }); expect(mocks.navigationMock.gotoURL).toHaveBeenCalledWith( expect.anything(), 'data:text/html;...', @@ -362,7 +378,14 @@ describe('NavigationRunner', () => { }); it('should prepare target for navigation', async () => { - await runner._setupNavigation({driver, navigation, requestedUrl, config, computedCache}); + await runner._setupNavigation({ + driver, + navigation, + requestedUrl, + config, + computedCache, + baseArtifacts, + }); expect(mocks.prepareMock.prepareTargetForIndividualNavigation).toHaveBeenCalled(); }); @@ -375,13 +398,15 @@ describe('NavigationRunner', () => { requestedUrl, config, computedCache, + baseArtifacts, }); expect(result).toEqual({warnings}); }); }); describe('_navigate', () => { - const run = () => runner._navigate({driver, navigation, requestedUrl, config, computedCache}); + const run = () => + runner._navigate({driver, navigation, requestedUrl, config, computedCache, baseArtifacts}); it('should navigate the page', async () => { await run(); 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 ea14353d8edc..cd17908c3d2e 100644 --- a/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js +++ b/lighthouse-core/test/fraggle-rock/gather/runner-helpers-test.js @@ -8,7 +8,7 @@ const helpers = require('../../../fraggle-rock/gather/runner-helpers.js'); const Gatherer = require('../../../fraggle-rock/gather/base-gatherer.js'); const {defaultSettings} = require('../../../config/constants.js'); -const {createMockDriver, createMockGathererInstance} = require('./mock-driver.js'); +const {createMockDriver, createMockGathererInstance, createMockBaseArtifacts} = require('./mock-driver.js'); // eslint-disable-line max-len /* eslint-env jest */ @@ -92,6 +92,8 @@ describe('collectPhaseArtifacts', () => { let driver; /** @type {ReturnType} */ let mockDriver; + /** @type {LH.FRBaseArtifacts} */ + let baseArtifacts; function createGathererSet() { const timespan = createMockGathererInstance({supportedModes: ['timespan', 'navigation']}); @@ -121,6 +123,7 @@ describe('collectPhaseArtifacts', () => { stopInstrumentation: {}, getArtifact: {}, }; + baseArtifacts = createMockBaseArtifacts(); }); for (const phase_ of Object.keys(artifactState)) { @@ -133,6 +136,7 @@ describe('collectPhaseArtifacts', () => { artifactDefinitions, artifactState, phase, + baseArtifacts, gatherMode: /** @type {any} */ (gatherMode), computedCache: new Map(), settings: defaultSettings, @@ -157,6 +161,7 @@ describe('collectPhaseArtifacts', () => { artifactState, gatherMode: 'navigation', phase: 'getArtifact', + baseArtifacts, computedCache: new Map(), settings: defaultSettings, }); @@ -188,6 +193,7 @@ describe('collectPhaseArtifacts', () => { artifactState, gatherMode: 'navigation', phase: 'getArtifact', + baseArtifacts, computedCache: new Map(), settings: defaultSettings, }); @@ -220,6 +226,7 @@ describe('collectPhaseArtifacts', () => { artifactState, gatherMode: 'navigation', phase: 'getArtifact', + baseArtifacts, computedCache: new Map(), settings: defaultSettings, }); diff --git a/lighthouse-core/test/gather/gatherers/css-usage-test.js b/lighthouse-core/test/gather/gatherers/css-usage-test.js index 2a5dd2c19d23..eda00c61215f 100644 --- a/lighthouse-core/test/gather/gatherers/css-usage-test.js +++ b/lighthouse-core/test/gather/gatherers/css-usage-test.js @@ -9,7 +9,10 @@ const CSSUsage = require('../../../gather/gatherers/css-usage.js'); const {defaultSettings} = require('../../../config/constants.js'); -const {createMockDriver} = require('../../fraggle-rock/gather/mock-driver.js'); +const { + createMockDriver, + createMockBaseArtifacts, +} = require('../../fraggle-rock/gather/mock-driver.js'); const {flushAllTimersAndMicrotasks} = require('../../test-utils.js'); jest.useFakeTimers(); @@ -42,6 +45,7 @@ describe('.getArtifact', () => { url: 'https://example.com', gatherMode: 'snapshot', computedCache: new Map(), + baseArtifacts: createMockBaseArtifacts(), dependencies: {}, settings: defaultSettings, }; @@ -97,6 +101,7 @@ describe('.getArtifact', () => { url: 'https://example.com', gatherMode: 'timespan', computedCache: new Map(), + baseArtifacts: createMockBaseArtifacts(), dependencies: {}, settings: defaultSettings, }; @@ -152,6 +157,7 @@ describe('.getArtifact', () => { url: 'https://example.com', gatherMode: 'snapshot', computedCache: new Map(), + baseArtifacts: createMockBaseArtifacts(), dependencies: {}, settings: defaultSettings, }; diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index a901c0177c77..46a09b880877 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -54,6 +54,10 @@ interface UniversalBaseArtifacts { settings: Config.Settings; /** The timing instrumentation of the gather portion of a run. */ Timing: Artifacts.MeasureEntry[]; + /** Device which Chrome is running on. */ + HostFormFactor: 'desktop'|'mobile'; + /** The user agent string of the version of Chrome used. */ + HostUserAgent: string; } /** @@ -70,10 +74,6 @@ interface ContextualBaseArtifacts { * The set of base artifacts that were replaced by standard gatherers in Fraggle Rock. */ interface LegacyBaseArtifacts { - /** Device which Chrome is running on. */ - HostFormFactor: 'desktop'|'mobile'; - /** The user agent string of the version of Chrome used. */ - HostUserAgent: string; /** The user agent string that Lighthouse used to load the page. Set to the empty string if unknown. */ NetworkUserAgent: string; /** Information on detected tech stacks (e.g. JS libraries) used by the page. */ diff --git a/types/gatherer.d.ts b/types/gatherer.d.ts index 329f721af7d8..707a9aa25f7d 100644 --- a/types/gatherer.d.ts +++ b/types/gatherer.d.ts @@ -12,7 +12,7 @@ import ExecutionContext = require('../lighthouse-core/gather/driver/execution-co import Fetcher = require('../lighthouse-core/gather/fetcher'); import ArbitraryEqualityMap = require('../lighthouse-core/lib/arbitrary-equality-map'); -import {Artifacts, BaseArtifacts, GathererArtifacts} from './artifacts'; +import {Artifacts, BaseArtifacts, FRBaseArtifacts, GathererArtifacts} from './artifacts'; import Config from './config'; import {IcuMessage} from './lhr/i18n'; import Result from './lhr/lhr'; @@ -51,6 +51,8 @@ declare module Gatherer { gatherMode: GatherMode; /** The connection to the page being analyzed. */ driver: FRTransitionalDriver; + /** The set of base artifacts that are always collected. */ + baseArtifacts: FRBaseArtifacts; /** The cached results of computed artifacts. */ computedCache: Map; /** The set of available dependencies requested by the current gatherer. */ diff --git a/types/smokehouse.d.ts b/types/smokehouse.d.ts index 39879f8df66f..4fa7a57b3e32 100644 --- a/types/smokehouse.d.ts +++ b/types/smokehouse.d.ts @@ -14,6 +14,7 @@ declare global { audits: Record; requestedUrl: string; finalUrl: string | RegExp; + userAgent?: string | RegExp; runWarnings?: Array; runtimeError?: { code?: any;