Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tpw_0.26.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Nov 4, 2024
2 parents d7746a6 + 4276b07 commit e0b12fd
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 159 deletions.
2 changes: 1 addition & 1 deletion cli/test/smokehouse/frontends/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/* eslint-disable no-console */

import cloneDeep from 'lodash/cloneDeep.js';
import {cloneDeep} from 'lodash-es';

import smokeTests from '../core-tests.js';
import {runSmokehouse, getShardedDefinitions} from '../smokehouse.js';
Expand Down
2 changes: 1 addition & 1 deletion cli/test/smokehouse/frontends/smokehouse-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import path from 'path';
import fs from 'fs';
import url from 'url';

import cloneDeep from 'lodash/cloneDeep.js';
import {cloneDeep} from 'lodash-es';
import yargs from 'yargs';
import * as yargsHelpers from 'yargs/helpers';
import log from 'lighthouse-logger';
Expand Down
2 changes: 1 addition & 1 deletion cli/test/smokehouse/report-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* against the results actually collected from Lighthouse.
*/

import cloneDeep from 'lodash/cloneDeep.js';
import {cloneDeep} from 'lodash-es';
import log from 'lighthouse-logger';

import {LocalConsole} from './lib/local-console.js';
Expand Down
8 changes: 4 additions & 4 deletions cli/test/smokehouse/test-definitions/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ const expectations = {
'type': 'node',
'selector': 'body > section > button#button-name',
'snippet': '<button id="button-name">',
'explanation': 'Fix any of the following:\n Element does not have inner text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'explanation': 'Fix any of the following:\n Element does not have inner text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element does not have an implicit (wrapped) <label>\n Element does not have an explicit <label>\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'nodeLabel': 'body > section > button#button-name',
},
},
Expand Down Expand Up @@ -688,7 +688,7 @@ const expectations = {
'type': 'node',
'selector': 'body > section > form > input#input-button-name',
'snippet': '<input type="button" id="input-button-name">',
'explanation': 'Fix any of the following:\n Element has a value attribute and the value attribute is empty\n Element has no value attribute\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'explanation': 'Fix any of the following:\n Element has a value attribute and the value attribute is empty\n Element has no value attribute\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element does not have an implicit (wrapped) <label>\n Element does not have an explicit <label>\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'nodeLabel': 'body > section > form > input#input-button-name',
},
},
Expand All @@ -704,7 +704,7 @@ const expectations = {
'type': 'node',
'selector': 'body > section > input#input-image-alt',
'snippet': '<input type="image" id="input-image-alt">',
'explanation': 'Fix any of the following:\n Element has no alt attribute\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'explanation': 'Fix any of the following:\n Element has no alt attribute\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element does not have an implicit (wrapped) <label>\n Element does not have an explicit <label>',
'nodeLabel': 'body > section > input#input-image-alt',
},
},
Expand Down Expand Up @@ -866,7 +866,7 @@ const expectations = {
'type': 'node',
'selector': 'body > section > select#select-name',
'snippet': '<select id="select-name">',
'explanation': 'Fix any of the following:\n Form element does not have an implicit (wrapped) <label>\n Form element does not have an explicit <label>\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'explanation': 'Fix any of the following:\n Element does not have an implicit (wrapped) <label>\n Element does not have an explicit <label>\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'nodeLabel': 'body > section > select#select-name',
},
},
Expand Down
6 changes: 3 additions & 3 deletions core/config/config-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from 'path';
import {createRequire} from 'module';
import url from 'url';

import isDeepEqual from 'lodash/isEqual.js';
import {isEqual} from 'lodash-es';

import * as constants from './constants.js';
import ConfigPlugin from './config-plugin.js';
Expand Down Expand Up @@ -69,7 +69,7 @@ const mergeOptionsOfItems = function(items) {
* - `null` is treated similarly to `undefined` for whether a value should be overridden.
* - `overwriteArrays` controls array extension behavior:
* - true: Arrays are overwritten without any merging or concatenation.
* - false: Arrays are concatenated and de-duped by isDeepEqual.
* - false: Arrays are concatenated and de-duped by isEqual.
* - Objects are recursively merged.
* - If the `settings` key is encountered while traversing an object, its arrays are *always*
* overridden, not concatenated. (`overwriteArrays` is flipped to `true`)
Expand All @@ -90,7 +90,7 @@ function _mergeConfigFragment(base, extension, overwriteArrays = false) {
if (!Array.isArray(base)) throw new TypeError(`Expected array but got ${typeof base}`);
const merged = base.slice();
extension.forEach(item => {
if (!merged.some(candidate => isDeepEqual(candidate, item))) merged.push(item);
if (!merged.some(candidate => isEqual(candidate, item))) merged.push(item);
});

return merged;
Expand Down
5 changes: 5 additions & 0 deletions core/config/lr-mobile-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const config = {
settings: {
maxWaitForFcp: 15 * 1000,
maxWaitForLoad: 35 * 1000,
throttling: {
// Determined using PSI CPU benchmark median and
// https://lighthouse-cpu-throttling-calculator.vercel.app/
cpuSlowdownMultiplier: 1.5,
},
skipAudits: [
// Skip the h2 audit so it doesn't lie to us. See https://github.com/GoogleChrome/lighthouse/issues/6539
'uses-http2',
Expand Down
4 changes: 2 additions & 2 deletions core/gather/base-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import log from 'lighthouse-logger';
import isDeepEqual from 'lodash/isEqual.js';
import {isEqual} from 'lodash-es';

import {
getBrowserVersion, getBenchmarkIndex, getEnvironmentWarnings,
Expand Down Expand Up @@ -52,7 +52,7 @@ function deduplicateWarnings(warnings) {
const unique = [];

for (const warning of warnings) {
if (unique.some(existing => isDeepEqual(warning, existing))) continue;
if (unique.some(existing => isEqual(warning, existing))) continue;
unique.push(warning);
}

Expand Down
13 changes: 8 additions & 5 deletions core/gather/driver/network-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class NetworkMonitor extends NetworkMonitorEventEmitter {
* Returns whether the network is completely idle (i.e. there are 0 inflight network requests).
*/
isIdle() {
return this._isActiveIdlePeriod(0);
return this._isIdlePeriod(0);
}

/**
Expand All @@ -144,10 +144,13 @@ class NetworkMonitor extends NetworkMonitorEventEmitter {
const rootFrameRequest = requests.find(r => r.resourceType === 'Document');
const rootFrameId = rootFrameRequest?.frameId;

return this._isActiveIdlePeriod(
return this._isIdlePeriod(
0,
// Return true if it should be a candidate for critical.
request =>
request.frameId === rootFrameId &&
// WebSocket and Server-sent Events are typically long-lived and shouldn't be considered critical.
request.resourceType !== 'WebSocket' && request.resourceType !== 'EventSource' &&
(request.priority === 'VeryHigh' || request.priority === 'High')
);
}
Expand All @@ -156,7 +159,7 @@ class NetworkMonitor extends NetworkMonitorEventEmitter {
* Returns whether the network is semi-idle (i.e. there are 2 or fewer inflight network requests).
*/
is2Idle() {
return this._isActiveIdlePeriod(2);
return this._isIdlePeriod(2);
}

/**
Expand All @@ -166,15 +169,15 @@ class NetworkMonitor extends NetworkMonitorEventEmitter {
* @param {(request: NetworkRequest) => boolean} [requestFilter]
* @return {boolean}
*/
_isActiveIdlePeriod(allowedRequests, requestFilter) {
_isIdlePeriod(allowedRequests, requestFilter) {
if (!this._networkRecorder) return false;
const requests = this._networkRecorder.getRawRecords();
let inflightRequests = 0;

for (let i = 0; i < requests.length; i++) {
const request = requests[i];
if (request.finished) continue;
if (requestFilter && !requestFilter(request)) continue;
if (requestFilter?.(request) === false) continue;
if (NetworkRequest.isNonNetworkRequest(request)) continue;
inflightRequests++;
}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/arbitrary-equality-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import isDeepEqual from 'lodash/isEqual.js';
import {isEqual} from 'lodash-es';

/**
* @fileoverview This class is designed to allow maps with arbitrary equality functions.
Expand Down Expand Up @@ -73,7 +73,7 @@ class ArbitraryEqualityMap {
* @return {boolean}
*/
static deepEquals(objA, objB) {
return isDeepEqual(objA, objB);
return isEqual(objA, objB);
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from 'path';


import log from 'lighthouse-logger';
import isDeepEqual from 'lodash/isEqual.js';
import {isEqual} from 'lodash-es';

import {ReportScoring} from './scoring.js';
import {Audit} from './audits/audit.js';
Expand Down Expand Up @@ -308,7 +308,7 @@ class Runner {
...Object.keys(normalizedAuditSettings),
]);
for (const k of keys) {
if (!isDeepEqual(normalizedGatherSettings[k], normalizedAuditSettings[k])) {
if (!isEqual(normalizedGatherSettings[k], normalizedAuditSettings[k])) {
throw new Error(
`Cannot change settings between gathering and auditing…
Difference found at: \`${k}\`
Expand All @@ -318,8 +318,8 @@ vs
}
}

// Call `isDeepEqual` on the entire thing, just in case something was missed.
if (!isDeepEqual(normalizedGatherSettings, normalizedAuditSettings)) {
// Call `isEqual` on the entire thing, just in case something was missed.
if (!isEqual(normalizedGatherSettings, normalizedAuditSettings)) {
throw new Error('Cannot change settings between gathering and auditing');
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {expect} from 'expect';
import tsc from 'typescript';
import MessageParser from '@formatjs/icu-messageformat-parser';
import esMain from 'es-main';
import isDeepEqual from 'lodash/isEqual.js';
import {isEqual} from 'lodash-es';

import {Util} from '../../../shared/util.js';
import {collectAndBakeCtcStrings} from './bake-ctc-to-lhl.js';
Expand Down Expand Up @@ -660,7 +660,7 @@ function doPlaceholdersMatch(strings) {
// Technically placeholder `content` is not required to match by TC, but since
// `example` must match and any auto-generated `example` is copied from `content`,
// it would be confusing to let it differ when `example` is explicit.
return strings.every(val => isDeepEqual(val.ctc.placeholders, strings[0].ctc.placeholders));
return strings.every(val => isEqual(val.ctc.placeholders, strings[0].ctc.placeholders));
}

/**
Expand Down
16 changes: 13 additions & 3 deletions core/scripts/pptr-run-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,22 @@ async function evaluateInSession(session, fn, deps) {
* @return {Promise<R>}
*/
async function waitForFunction(session, fn, deps) {
let iterations = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
try {
return await evaluateInSession(session, fn, deps);
} catch {
} catch (err) {
// Random transient errors are common when first booting up.
// Only surface errors if this fails 10 times in a row (~5s)
if (iterations > 10) {
console.error(`Error waiting for function (#${iterations}):`);
console.error(err);
console.error('Retrying...');
}
await new Promise(r => setTimeout(r, 500));
} finally {
++iterations;
}
}
}
Expand Down Expand Up @@ -161,7 +171,7 @@ async function waitForLighthouseReady() {

const panel = LighthousePanel.LighthousePanel.instance();

const button = panel.contentElement.querySelector('devtools-button,button');
const button = panel.contentElement.querySelector('.vbox.flex-auto').shadowRoot.querySelector('devtools-button,button');
if (button.disabled) throw new Error('Start button disabled');

const targetManager = TargetManager.TargetManager.instance();
Expand Down Expand Up @@ -213,7 +223,7 @@ async function runLighthouse() {
// In CI clicking the start button just once is flaky and can cause a timeout.
// Therefore, keep clicking the button until we detect that the run started.
const intervalHandle = setInterval(() => {
const button = panel.contentElement.querySelector('devtools-button,button');
const button = panel.contentElement.querySelector('.vbox.flex-auto').shadowRoot.querySelector('devtools-button,button');
button.click();
}, 100);

Expand Down
16 changes: 16 additions & 0 deletions core/test/gather/driver/network-monitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,22 @@ describe('NetworkMonitor', () => {
expect(monitor.is2Idle()).toBe(false);
expect(monitor.isCriticalIdle()).toBe(true);
});

it('should treat longlived stuff as noncritical', () => {
const messages = networkRecordsToDevtoolsLog([
// WebSockets usually dont have a priority on them. SSE usually is a 'High'
{url: 'http://example.com/ws', priority: undefined, requestId: `314.1`, resourceType: 'WebSocket'},
{url: 'http://example.com/sse', priority: 'High', requestId: `314.2`, resourceType: 'EventSource'},
], {skipVerification: true}).filter(event => event.method === 'Network.requestWillBeSent');

for (const message of messages) {
rootDispatch(message);
}

expect(monitor.isCriticalIdle()).toBe(true);
expect(monitor.isIdle()).toBe(false);
expect(monitor.is2Idle()).toBe(true);
});
});

describe('#findNetworkQuietPeriods', () => {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"@types/google.analytics": "0.0.39",
"@types/jpeg-js": "^0.3.7",
"@types/jsdom": "^16.2.13",
"@types/lodash": "^4.14.178",
"@types/lodash-es": "^4.17.12",
"@types/mocha": "^9.0.0",
"@types/node": "*",
"@types/pako": "^1.0.1",
Expand Down Expand Up @@ -167,7 +167,7 @@
"pako": "^2.0.3",
"preact": "^10.7.2",
"pretty-json-stringify": "^0.0.2",
"puppeteer": "^23.3.0",
"puppeteer": "^23.5.2",
"resolve": "^1.22.1",
"rollup": "^2.52.7",
"rollup-plugin-polyfill-node": "^0.12.0",
Expand All @@ -182,8 +182,8 @@
},
"dependencies": {
"@paulirish/trace_engine": "0.0.32",
"@sentry/node": "^6.17.4",
"axe-core": "^4.10.0",
"@sentry/node": "^7.0.0",
"axe-core": "^4.10.2",
"chrome-launcher": "^1.1.2",
"configstore": "^5.0.1",
"csp_evaluator": "1.1.1",
Expand All @@ -195,12 +195,12 @@
"js-library-detector": "^6.7.0",
"lighthouse-logger": "^2.0.1",
"lighthouse-stack-packs": "1.12.1",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"lookup-closest-locale": "6.2.0",
"metaviewport-parser": "0.3.0",
"open": "^8.4.0",
"parse-cache-control": "1.0.1",
"puppeteer-core": "^23.3.0",
"puppeteer-core": "^23.5.2",
"robots-parser": "^3.0.1",
"semver": "^5.3.0",
"speedline-core": "^1.4.3",
Expand Down
8 changes: 4 additions & 4 deletions shared/localization/swap-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import _set from 'lodash/set.js';
import _get from 'lodash/get.js';
import {set} from 'lodash-es';
import {get} from 'lodash-es';

import * as format from './format.js';

Expand Down Expand Up @@ -72,7 +72,7 @@ function swapLocale(lhr, requestedLocale) {

// If the path isn't valid or the value isn't a string, there's no point in trying to replace it.
/** @type {unknown} */
const originalString = _get(lhr, path);
const originalString = get(lhr, path);
if (typeof originalString !== 'string') {
continue;
}
Expand All @@ -96,7 +96,7 @@ function swapLocale(lhr, requestedLocale) {
}

// Write string back into the LHR.
_set(lhr, path, relocalizedString);
set(lhr, path, relocalizedString);
}
}

Expand Down
Loading

0 comments on commit e0b12fd

Please sign in to comment.