Skip to content

Commit

Permalink
fix: default config (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhenson authored Dec 2, 2021
1 parent 202c691 commit e644aed
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 17 deletions.
61 changes: 57 additions & 4 deletions src/__snapshots__/lighthouseConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,63 @@

exports[`config should match snapshot 1`] = `
Object {
"extends": "lighthouse:default",
"settings": Object {
"emulatedFormFactor": "mobile",
"throttling": Object {
"desktop": Object {
"extends": "lighthouse:default",
"settings": Object {
"emulatedUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4420.0 Safari/537.36 Chrome-Lighthouse",
"formFactor": "desktop",
"maxWaitForFcp": 15000,
"maxWaitForLoad": 35000,
"screenEmulation": Object {
"deviceScaleFactor": 1,
"disabled": false,
"height": 940,
"mobile": false,
"width": 1350,
},
"skipAudits": Array [
"uses-http2",
],
"throttling": Object {
"cpuSlowdownMultiplier": 1,
"downloadThroughputKbps": 0,
"requestLatencyMs": 0,
"rttMs": 40,
"throughputKbps": 10240,
"uploadThroughputKbps": 0,
},
},
},
"mobile": Object {
"extends": "lighthouse:default",
"settings": Object {
"maxWaitForFcp": 15000,
"maxWaitForLoad": 35000,
"skipAudits": Array [
"uses-http2",
],
},
},
"throttling": Object {
"DEVTOOLS_RTT_ADJUSTMENT_FACTOR": 3.75,
"DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR": 0.9,
"desktopDense4G": Object {
"cpuSlowdownMultiplier": 1,
"downloadThroughputKbps": 0,
"requestLatencyMs": 0,
"rttMs": 40,
"throughputKbps": 10240,
"uploadThroughputKbps": 0,
},
"mobileRegular3G": Object {
"cpuSlowdownMultiplier": 4,
"downloadThroughputKbps": 630,
"requestLatencyMs": 1125,
"rttMs": 300,
"throughputKbps": 700,
"uploadThroughputKbps": 630,
},
"mobileSlow4G": Object {
"cpuSlowdownMultiplier": 4,
"downloadThroughputKbps": 1474.5600000000002,
"requestLatencyMs": 562.5,
Expand Down
78 changes: 67 additions & 11 deletions src/lighthouseConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// taken from https://github.com/GoogleChrome/lighthouse/blob/b834427d676dc77e112d124ca42cc588f896950e/lighthouse-core/config/constants.js#L8-L41
// https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/constants.js
/**
* Adjustments needed for DevTools network throttling to simulate
* more realistic network conditions.
Expand All @@ -24,7 +24,7 @@ export const throttling = {
// These values partially align with WebPageTest's definition of "Regular 3G".
// These values are meant to roughly align with Chrome UX report's 3G definition which are based
// on HTTP RTT of 300-1400ms and downlink throughput of <700kbps.
mobileRegluar3G: {
mobileRegular3G: {
rttMs: 300,
throughputKbps: 700,
requestLatencyMs: 300 * DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
Expand All @@ -44,16 +44,72 @@ export const throttling = {
}
};

// https://github.com/GoogleChrome/lighthouse/blob/master/docs/configuration.md
// okay, maybe a little different from...
// https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/perf-config.js
export default {
/**
* @type {Required<LH.SharedFlagsSettings['screenEmulation']>}
*/
const MOTOG4_EMULATION_METRICS = {
mobile: true,
width: 360,
height: 640,
// Moto G4 is really 3, but a higher value here works against
// our perf recommendations.
// https://github.com/GoogleChrome/lighthouse/issues/10741#issuecomment-626903508
deviceScaleFactor: 2.625,
disabled: false
};

/**
* Desktop metrics adapted from emulated_devices/module.json
* @type {Required<LH.SharedFlagsSettings['screenEmulation']>}
*/
const DESKTOP_EMULATION_METRICS = {
mobile: false,
width: 1350,
height: 940,
deviceScaleFactor: 1,
disabled: false
};

const screenEmulationMetrics = {
mobile: MOTOG4_EMULATION_METRICS,
desktop: DESKTOP_EMULATION_METRICS
};

// eslint-disable-next-line max-len
const MOTOG4_USERAGENT =
'Mozilla/5.0 (Linux; Android 7.0; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4420.0 Mobile Safari/537.36 Chrome-Lighthouse';
// eslint-disable-next-line max-len
const DESKTOP_USERAGENT =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4420.0 Safari/537.36 Chrome-Lighthouse';

const userAgents = {
mobile: MOTOG4_USERAGENT,
desktop: DESKTOP_USERAGENT
};

// https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/lr-desktop-config.js
export const desktop = {
extends: 'lighthouse:default',
settings: {
maxWaitForFcp: 15 * 1000,
maxWaitForLoad: 35 * 1000,
formFactor: 'desktop',
throttling: throttling.desktopDense4G,
screenEmulation: screenEmulationMetrics.desktop,
emulatedUserAgent: userAgents.desktop,
// Skip the h2 audit so it doesn't lie to us. See https://github.com/GoogleChrome/lighthouse/issues/6539
skipAudits: ['uses-http2']
}
};

// https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/lr-mobile-config.js
export const mobile = {
extends: 'lighthouse:default',
settings: {
emulatedFormFactor: 'mobile',
// "These exact figures are used as Lighthouse's throttling default"
// https://github.com/GoogleChrome/lighthouse/blob/8f500e00243e07ef0a80b39334bedcc8ddc8d3d0/lighthouse-core/config/constants.js#L19-L26
// https://github.com/GoogleChrome/lighthouse/blob/master/docs/throttling.md
throttling: throttling.mobileSlow4G
maxWaitForFcp: 15 * 1000,
maxWaitForLoad: 35 * 1000,
// lighthouse:default is mobile by default
// Skip the h2 audit so it doesn't lie to us. See https://github.com/GoogleChrome/lighthouse/issues/6539
skipAudits: ['uses-http2']
}
};
2 changes: 1 addition & 1 deletion src/lighthouseConfig.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from './lighthouseConfig';
import * as config from './lighthouseConfig';

describe('config', () => {
it('should match snapshot', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/localLighthouse.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import fs from 'fs';
import get from 'lodash.get';
import lighthousePersist from '@foo-software/lighthouse-persist';
import lighthouseDefaultConfig, { throttling } from './lighthouseConfig';
import { desktop, mobile, throttling } from './lighthouseConfig';
import options from './lighthouseOptions';
import writeResults from './helpers/writeResults';
import { NAME } from './constants';

const defaultLighthouseConfigs = {
desktop,
mobile
};

const getScoresFromFloat = scores =>
Object.keys(scores).reduce(
(accumulator, current) => ({
Expand Down Expand Up @@ -40,6 +45,8 @@ export const localLighthouse = async ({
? 'desktopDense4G'
: throttlingParam;

const lighthouseDefaultConfig = defaultLighthouseConfigs[emulatedFormFactor];

// the default config combined with overriding query params
const fullConfig = {
...lighthouseDefaultConfig,
Expand Down

0 comments on commit e644aed

Please sign in to comment.