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

fix: default config #58

Merged
merged 3 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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