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: add new base artifact, HostFormFactor #9923

Merged
merged 10 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -12,6 +12,7 @@
const expectations = [
{
artifacts: {
HostFormFactor: 'desktop',
Stacks: [{
id: 'jquery',
}, {
Expand Down
5 changes: 3 additions & 2 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,15 @@ class GatherRunner {

const {emulatedFormFactor} = options.settings;
// Whether Lighthouse was run on a mobile device (i.e. not on a desktop machine).
const IsMobileHost = hostUserAgent.includes('Android') || hostUserAgent.includes('Mobile');
const HostFormFactor = /android|mobile/i.test(hostUserAgent) ? 'mobile' : 'desktop';
Copy link
Collaborator Author

@connorjclark connorjclark Nov 6, 2019

Choose a reason for hiding this comment

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

paul called me names (not out loud, but in his head) for wanting to use a regex here

Copy link
Member

Choose a reason for hiding this comment

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

const TestedAsMobileDevice = emulatedFormFactor === 'mobile' ||
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
(emulatedFormFactor !== 'desktop' && IsMobileHost);
(emulatedFormFactor !== 'desktop' && HostFormFactor === 'mobile');

return {
fetchTime: (new Date()).toJSON(),
LighthouseRunWarnings: [],
TestedAsMobileDevice,
HostFormFactor,
HostUserAgent: hostUserAgent,
NetworkUserAgent: '', // updated later
BenchmarkIndex: 0, // updated later
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/scripts/build-report-for-autodeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async function generateErrorLHR() {
`Something went wrong with recording the trace over your page load. Please run Lighthouse again. (NO_FCP)`, // eslint-disable-line max-len
],
TestedAsMobileDevice: true,
HostFormFactor: 'desktop',
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
HostUserAgent: 'Mozilla/5.0 ErrorUserAgent Chrome/66',
NetworkUserAgent: 'Mozilla/5.0 ErrorUserAgent Chrome/66',
BenchmarkIndex: 1000,
Expand Down
26 changes: 26 additions & 0 deletions lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,32 @@ describe('GatherRunner', function() {
});
});

describe.only('collects HostFormFactor as an artifact', () => {
const requestedUrl = 'https://example.com';

function test(name, userAgent, expectedValue) {
it(name, async () => {
const driver = Object.assign({}, fakeDriver, {
getBrowserVersion() {
return Promise.resolve({userAgent: 'Android'});
},
});
const config = new Config({
passes: [],
settings: {},
});
const options = {requestedUrl, driver, settings: config.settings};

const results = await GatherRunner.run(config.passes, options);
expect(results.HostFormFactor).toBe('mobile');
});
}

test('works when running on mobile device', 'some mobile ua', 'mobile');
test('works when running on android device', 'some android ua', 'mobile');
test('works when running on desktop device', 'some desktop ua', 'desktop');
});

it('sets up the driver to begin emulation when all emulation flags are undefined', () => {
const tests = {
calledDeviceEmulation: false,
Expand Down
2 changes: 2 additions & 0 deletions types/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ declare global {
LighthouseRunWarnings: string[];
/** Whether the page was loaded on either a real or emulated mobile device. */
TestedAsMobileDevice: boolean;
/** Device which Chrome is running on. */
HostFormFactor: 'desktop'|'mobile';
Copy link
Member

Choose a reason for hiding this comment

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

TestedAsMobileDevice
HostUserAgent
NetworkUserAgent
HostFormFactor
emulatedFormFactor
deviceScreenEmulationMethod

https://www.theonion.com/taco-bells-five-ingredients-combined-in-totally-new-way-1819564909

/** The user agent string of the version of Chrome used. */
HostUserAgent: string;
/** The user agent string that Lighthouse used to load the page. */
Expand Down