-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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(fr): convert additional base artifacts #12594
Changes from 8 commits
2615e18
0ab0013
e87c49b
0d30d23
7136c72
3a11584
7801b5d
804b2de
ff37b86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @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<LH.Artifacts['HostFormFactor']>} | ||
*/ | ||
async getArtifact(context) { | ||
const userAgent = context.dependencies.HostUserAgent; | ||
return userAgent.includes('Android') || userAgent.includes('Mobile') ? 'mobile' : 'desktop'; | ||
} | ||
} | ||
|
||
module.exports = HostFormFactor; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @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<LH.Artifacts['HostUserAgent']>} | ||
*/ | ||
getArtifact(context) { | ||
return getBrowserVersion(context.driver.defaultSession).then(v => v.userAgent); | ||
patrickhulce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
module.exports = HostUserAgent; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,40 +15,17 @@ const {initializeConfig} = require('../../../fraggle-rock/config/config.js'); | |
const {createMockDriver} = require('./mock-driver.js'); | ||
const LighthouseError = require('../../../lib/lh-error.js'); | ||
|
||
/** @param {{userAgent: string}} params */ | ||
function getMockDriverForArtifacts({userAgent}) { | ||
function getMockDriverForArtifacts() { | ||
const driverMock = createMockDriver(); | ||
driverMock._session.sendCommand.mockResponse('Browser.getVersion', { | ||
userAgent, | ||
product: '', | ||
}); | ||
|
||
driverMock._executionContext.evaluate.mockResolvedValue(500); | ||
|
||
return driverMock; | ||
} | ||
|
||
describe('getBaseArtifacts', () => { | ||
let driverMock = getMockDriverForArtifacts({userAgent: 'Desktop Chrome'}); | ||
let driverMock = getMockDriverForArtifacts(); | ||
|
||
beforeEach(() => { | ||
driverMock = getMockDriverForArtifacts({userAgent: 'Desktop Chrome'}); | ||
}); | ||
|
||
it('should fetch the desktop user agent', async () => { | ||
const {config} = initializeConfig(undefined, {gatherMode: 'navigation'}); | ||
const artifacts = await getBaseArtifacts(config, driverMock.asDriver()); | ||
expect(artifacts.HostUserAgent).toEqual('Desktop Chrome'); | ||
expect(artifacts.HostFormFactor).toEqual('desktop'); | ||
}); | ||
|
||
it('should fetch the mobile user agent', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'll probably want to bring these tests back when we have the breaking change for 9.0 to merge those |
||
driverMock = getMockDriverForArtifacts({userAgent: 'Mobile Chrome'}); | ||
|
||
const {config} = initializeConfig(undefined, {gatherMode: 'navigation'}); | ||
const artifacts = await getBaseArtifacts(config, driverMock.asDriver()); | ||
expect(artifacts.HostUserAgent).toEqual('Mobile Chrome'); | ||
expect(artifacts.HostFormFactor).toEqual('mobile'); | ||
driverMock = getMockDriverForArtifacts(); | ||
}); | ||
|
||
it('should fetch benchmark index', async () => { | ||
|
@@ -72,7 +49,7 @@ describe('finalizeArtifacts', () => { | |
|
||
beforeEach(async () => { | ||
const {config} = initializeConfig(undefined, {gatherMode: 'navigation'}); | ||
const driver = getMockDriverForArtifacts({userAgent: 'Desktop Chrome'}).asDriver(); | ||
const driver = getMockDriverForArtifacts().asDriver(); | ||
baseArtifacts = await getBaseArtifacts(config, driver); | ||
baseArtifacts.URL = {requestedUrl: 'http://example.com', finalUrl: 'https://example.com'}; | ||
gathererArtifacts = {}; | ||
|
@@ -81,6 +58,7 @@ describe('finalizeArtifacts', () => { | |
it('should merge the two objects', () => { | ||
baseArtifacts.LighthouseRunWarnings = [{i18nId: '1', formattedDefault: 'Yes'}]; | ||
gathererArtifacts.LighthouseRunWarnings = [{i18nId: '2', formattedDefault: 'No'}]; | ||
gathererArtifacts.HostUserAgent = 'Desktop Chrome'; | ||
|
||
const winningError = new LighthouseError(LighthouseError.errors.NO_LCP); | ||
baseArtifacts.PageLoadError = new LighthouseError(LighthouseError.errors.NO_FCP); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,7 +114,7 @@ describe('NavigationRunner', () => { | |
|
||
it('should collect base artifacts', async () => { | ||
const {baseArtifacts} = await runner._setup({driver, config, requestedUrl}); | ||
expect(baseArtifacts).toMatchObject({HostUserAgent: 'Chrome', URL: {requestedUrl}}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
expect(baseArtifacts).toMatchObject({URL: {requestedUrl}}); | ||
}); | ||
|
||
it('should prepare the target for navigation', async () => { | ||
|
@@ -123,8 +123,8 @@ describe('NavigationRunner', () => { | |
}); | ||
|
||
it('should prepare the target for navigation *after* base artifact collection', async () => { | ||
mockDriver._session.sendCommand.mockReset(); | ||
mockDriver._session.sendCommand.mockRejectedValue(new Error('Not available')); | ||
mockDriver._executionContext.evaluate.mockReset(); | ||
mockDriver._executionContext.evaluate.mockRejectedValue(new Error('Not available')); | ||
const setupPromise = runner._setup({driver, config, requestedUrl}); | ||
await expect(setupPromise).rejects.toThrowError(/Not available/); | ||
expect(mocks.prepareMock.prepareTargetForNavigationMode).not.toHaveBeenCalled(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,14 +69,7 @@ declare global { | |
trace?: Trace; | ||
} | ||
|
||
export type PhaseArtifact = | | ||
LH.GathererArtifacts[keyof LH.GathererArtifacts] | | ||
LH.Artifacts['devtoolsLogs'] | | ||
LH.Artifacts['traces'] | | ||
LH.Artifacts['WebAppManifest'] | | ||
LH.Artifacts['InstallabilityErrors'] | | ||
LH.Artifacts['Stacks']; | ||
export type PhaseResultNonPromise = void|PhaseArtifact | ||
Comment on lines
-72
to
-79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only difference here should be |
||
export type PhaseResultNonPromise = void | LH.GathererArtifacts[keyof LH.GathererArtifacts]; | ||
export type PhaseResult = PhaseResultNonPromise | Promise<PhaseResultNonPromise> | ||
|
||
export type GatherMode = 'snapshot'|'timespan'|'navigation'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time to start a breaking changes v9 issue to merge these :)