misc(driver): rename ForFCP to ForFcp (#10516)

This commit is contained in:
Patrick Hulce 2020-03-30 13:23:43 -05:00 коммит произвёл GitHub
Родитель 61207bebed
Коммит 8443176392
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 41 добавлений и 33 удалений

Просмотреть файл

@ -65,7 +65,7 @@ const smokeTests = [{
}, {
id: 'metrics',
expectations: require('./tricky-metrics/expectations.js'),
config: require('../../../../lighthouse-core/config/no-throttling-config.js'),
config: require('./tricky-metrics/no-throttling-config.js'),
}, {
id: 'mixed-content',
expectations: require('./mixed-content/mixed-content-expectations.js'),

Просмотреть файл

@ -7,7 +7,9 @@
/**
* @type {Array<Smokehouse.ExpectedRunnerResult>}
* Expected Lighthouse audit values for tricky metrics tests
* Expected Lighthouse audit values for tricky metrics tests that previously failed to be computed.
* We only place lower bounds because we are checking that these metrics *can* be computed and that
* we wait long enough to compute them. Upper bounds aren't very helpful here and tend to cause flaky failures.
*/
module.exports = [
{
@ -16,12 +18,12 @@ module.exports = [
finalUrl: 'http://localhost:10200/tricky-tti.html',
audits: {
'first-cpu-idle': {
// stalls for 5 seconds, 5 seconds out, so should be around 10s
numericValue: '>9000',
// stalls for ~5 seconds, ~5 seconds out, so should be at least ~10s
numericValue: '>9900',
},
'interactive': {
// stalls for 5 seconds, 5 seconds out, so should be around 10s
numericValue: '>9000',
// stalls for ~5 seconds, ~5 seconds out, so should be at least ~10s
numericValue: '>9900',
},
},
},
@ -32,11 +34,11 @@ module.exports = [
finalUrl: 'http://localhost:10200/tricky-tti-late-fcp.html',
audits: {
'first-cpu-idle': {
// FCP at ~5 seconds out
// FCP at least ~5 seconds out
numericValue: '>4900',
},
'interactive': {
// FCP at ~5 seconds out
// FCP at least ~5 seconds out
numericValue: '>4900',
},
},

Просмотреть файл

@ -5,8 +5,14 @@
*/
'use strict';
/**
* A config with no throttling used for tricky-metrics tests.
* Those class of tricky metrics need to use observed metrics and DevTools throttling has too many bugs
* to capture the nuances we're testing.
*/
/** @type {LH.Config.Json} */
const perfConfig = {
const noThrottlingConfig = {
extends: 'lighthouse:default',
settings: {
throttlingMethod: 'provided',
@ -14,4 +20,4 @@ const perfConfig = {
},
};
module.exports = perfConfig;
module.exports = noThrottlingConfig;

Просмотреть файл

@ -652,19 +652,19 @@ class Driver {
/**
* Returns a promise that resolve when a frame has a FCP.
* @param {number} pauseAfterFcpMs
* @param {number} maxWaitForFCPMs
* @param {number} maxWaitForFcpMs
* @return {{promise: Promise<void>, cancel: function(): void}}
*/
_waitForFCP(pauseAfterFcpMs, maxWaitForFCPMs) {
_waitForFcp(pauseAfterFcpMs, maxWaitForFcpMs) {
/** @type {(() => void)} */
let cancel = () => {
throw new Error('_waitForFCP.cancel() called before it was defined');
throw new Error('_waitForFcp.cancel() called before it was defined');
};
const promise = new Promise((resolve, reject) => {
const maxWaitTimeout = setTimeout(() => {
reject(new LHError(LHError.errors.NO_FCP));
}, maxWaitForFCPMs);
}, maxWaitForFcpMs);
/** @type {NodeJS.Timeout|undefined} */
let loadTimeout;
@ -927,8 +927,8 @@ class Driver {
let maxTimeoutHandle;
// Listener for FCP. Resolves pauseAfterFcpMs ms after first FCP event.
const waitForFCP = maxWaitForFcpMs ?
this._waitForFCP(pauseAfterFcpMs, maxWaitForFcpMs) :
const waitForFcp = maxWaitForFcpMs ?
this._waitForFcp(pauseAfterFcpMs, maxWaitForFcpMs) :
this._waitForNothing();
// Listener for onload. Resolves pauseAfterLoadMs ms after load.
const waitForLoadEvent = this._waitForLoadEvent(pauseAfterLoadMs);
@ -940,7 +940,7 @@ class Driver {
// Wait for all initial load promises. Resolves on cleanup function the clears load
// timeout timer.
const loadPromise = Promise.all([
waitForFCP.promise,
waitForFcp.promise,
waitForLoadEvent.promise,
waitForNetworkIdle.promise,
]).then(() => {
@ -980,7 +980,7 @@ class Driver {
]);
maxTimeoutHandle && clearTimeout(maxTimeoutHandle);
waitForFCP.cancel();
waitForFcp.cancel();
waitForLoadEvent.cancel();
waitForNetworkIdle.cancel();
waitForCPUIdle.cancel();
@ -1070,17 +1070,17 @@ class Driver {
* possible workaround.
* Resolves on the url of the loaded page, taking into account any redirects.
* @param {string} url
* @param {{waitForFCP?: boolean, waitForLoad?: boolean, waitForNavigated?: boolean, passContext?: LH.Gatherer.PassContext}} options
* @param {{waitForFcp?: boolean, waitForLoad?: boolean, waitForNavigated?: boolean, passContext?: LH.Gatherer.PassContext}} options
* @return {Promise<string>}
*/
async gotoURL(url, options = {}) {
const waitForFCP = options.waitForFCP || false;
const waitForFcp = options.waitForFcp || false;
const waitForNavigated = options.waitForNavigated || false;
const waitForLoad = options.waitForLoad || false;
const passContext = /** @type {Partial<LH.Gatherer.PassContext>} */ (options.passContext || {});
const disableJS = passContext.disableJavaScript || false;
if (waitForNavigated && (waitForFCP || waitForLoad)) {
if (waitForNavigated && (waitForFcp || waitForLoad)) {
throw new Error('Cannot use both waitForNavigated and another event, pick just one');
}
@ -1119,7 +1119,7 @@ class Driver {
if (typeof maxFCPMs !== 'number') maxFCPMs = constants.defaultSettings.maxWaitForFcp;
/* eslint-enable max-len */
if (!waitForFCP) maxFCPMs = undefined;
if (!waitForFcp) maxFCPMs = undefined;
await this._waitForFullyLoaded(pauseAfterFcpMs, pauseAfterLoadMs, networkQuietThresholdMs,
cpuQuietThresholdMs, maxWaitMs, maxFCPMs);
}

Просмотреть файл

@ -77,7 +77,7 @@ class GatherRunner {
log.time(status);
try {
const finalUrl = await driver.gotoURL(passContext.url, {
waitForFCP: passContext.passConfig.recordTrace,
waitForFcp: passContext.passConfig.recordTrace,
waitForLoad: true,
passContext,
});

Просмотреть файл

@ -125,7 +125,7 @@ async function flushAllTimersAndMicrotasks(ms = 1000) {
* @typedef DriverMockMethods
* @property {ReturnType<typeof createMockOnceFn>} on
* @property {ReturnType<typeof createMockOnceFn>} once
* @property {ReturnType<typeof createMockWaitForFn>} _waitForFCP
* @property {ReturnType<typeof createMockWaitForFn>} _waitForFcp
* @property {ReturnType<typeof createMockWaitForFn>} _waitForLoadEvent
* @property {ReturnType<typeof createMockWaitForFn>} _waitForNetworkIdle
* @property {ReturnType<typeof createMockWaitForFn>} _waitForCPUIdle
@ -544,9 +544,9 @@ describe('.gotoURL', () => {
describe('when waitForLoad', () => {
const url = 'https://example.com';
['FCP', 'LoadEvent', 'NetworkIdle', 'CPUIdle'].forEach(name => {
['Fcp', 'LoadEvent', 'NetworkIdle', 'CPUIdle'].forEach(name => {
it(`should wait for ${name}`, async () => {
driver._waitForFCP = createMockWaitForFn();
driver._waitForFcp = createMockWaitForFn();
driver._waitForLoadEvent = createMockWaitForFn();
driver._waitForNetworkIdle = createMockWaitForFn();
driver._waitForCPUIdle = createMockWaitForFn();
@ -554,14 +554,14 @@ describe('.gotoURL', () => {
// @ts-ignore - dynamic property access, tests will definitely fail if the property were to change
const waitForResult = driver[`_waitFor${name}`];
const otherWaitForResults = [
driver._waitForFCP,
driver._waitForFcp,
driver._waitForLoadEvent,
driver._waitForNetworkIdle,
driver._waitForCPUIdle,
].filter(l => l !== waitForResult);
const loadPromise = makePromiseInspectable(driver.gotoURL(url, {
waitForFCP: true,
waitForFcp: true,
waitForLoad: true,
}));
@ -655,11 +655,11 @@ describe('.gotoURL', () => {
});
});
describe('._waitForFCP', () => {
describe('._waitForFcp', () => {
it('should not resolve until FCP fires', async () => {
driver.on = driver.once = createMockOnceFn();
const waitPromise = makePromiseInspectable(driver._waitForFCP(0, 60 * 1000).promise);
const waitPromise = makePromiseInspectable(driver._waitForFcp(0, 60 * 1000).promise);
const listener = driver.on.findListener('Page.lifecycleEvent');
await flushAllTimersAndMicrotasks();
@ -678,7 +678,7 @@ describe('._waitForFCP', () => {
it('should wait for pauseAfterFcpMs after FCP', async () => {
driver.on = driver.once = createMockOnceFn();
const waitPromise = makePromiseInspectable(driver._waitForFCP(5000, 60 * 1000).promise);
const waitPromise = makePromiseInspectable(driver._waitForFcp(5000, 60 * 1000).promise);
const listener = driver.on.findListener('Page.lifecycleEvent');
await flushAllTimersAndMicrotasks();
@ -698,7 +698,7 @@ describe('._waitForFCP', () => {
it('should timeout', async () => {
driver.on = driver.once = createMockOnceFn();
const waitPromise = makePromiseInspectable(driver._waitForFCP(0, 5000).promise);
const waitPromise = makePromiseInspectable(driver._waitForFcp(0, 5000).promise);
await flushAllTimersAndMicrotasks();
expect(waitPromise).not.toBeDone('Resolved before timeout');
@ -713,7 +713,7 @@ describe('._waitForFCP', () => {
driver.on = driver.once = createMockOnceFn();
driver.off = jest.fn();
const {promise: rawPromise, cancel} = driver._waitForFCP(0, 5000);
const {promise: rawPromise, cancel} = driver._waitForFcp(0, 5000);
const waitPromise = makePromiseInspectable(rawPromise);
await flushAllTimersAndMicrotasks();