diff --git a/lighthouse-core/audits/load-fast-enough-for-pwa.js b/lighthouse-core/audits/load-fast-enough-for-pwa.js index c7c73cea6440..c276e6a4959f 100644 --- a/lighthouse-core/audits/load-fast-enough-for-pwa.js +++ b/lighthouse-core/audits/load-fast-enough-for-pwa.js @@ -16,6 +16,9 @@ const Audit = require('./audit'); const mobileThrottling = require('../config/constants').throttling.mobileSlow4G; const Interactive = require('../gather/computed/metrics/interactive.js'); +const displayValueText = `Interactive at %d\xa0s`; +const displayValueTextWithOverride = `Interactive on simulated mobile network at %d\xa0s`; + // Maximum TTI to be considered "fast" for PWA baseline checklist // https://developers.google.com/web/progressive-web-apps/checklist const MAXIMUM_TTI = 10 * 1000; @@ -48,11 +51,14 @@ class LoadFastEnough4Pwa extends Audit { // If throttling was default devtools or lantern slow 4G throttling, then reuse the given settings // Otherwise, we'll force the usage of lantern slow 4G. const settingOverrides = {throttlingMethod: 'simulate', throttling: mobileThrottling}; - const settings = - context.settings.throttlingMethod !== 'provided' && - isDeepEqual(context.settings.throttling, mobileThrottling) - ? context.settings - : Object.assign({}, context.settings, settingOverrides); + + // Override settings for interactive if provided throttling was used and network + // throttling was not consistent with standard `mobile network throttling` + const override = context.settings.throttlingMethod === 'provided' && + !isDeepEqual(context.settings.throttling, mobileThrottling); + + const settings = !override? context.settings: + Object.assign({}, context.settings, settingOverrides); const metricComputationData = {trace, devtoolsLog, settings}; const tti = await Interactive.request(metricComputationData, context); @@ -64,7 +70,7 @@ class LoadFastEnough4Pwa extends Audit { /** @type {string|undefined} */ let explanation; if (!score) { - displayValue = [`Interactive at %d\xa0s`, tti.timing / 1000]; + displayValue = [override?displayValueTextWithOverride: displayValueText, tti.timing / 1000]; explanation = 'Your page loads too slowly and is not interactive within 10 seconds. ' + 'Look at the opportunities and diagnostics in the "Performance" section to learn how to ' + 'improve.'; diff --git a/lighthouse-core/test/audits/load-fast-enough-for-pwa-test.js b/lighthouse-core/test/audits/load-fast-enough-for-pwa-test.js index 734f86e8e94a..e6d54d86073d 100644 --- a/lighthouse-core/test/audits/load-fast-enough-for-pwa-test.js +++ b/lighthouse-core/test/audits/load-fast-enough-for-pwa-test.js @@ -78,4 +78,27 @@ describe('PWA: load-fast-enough-for-pwa audit', () => { expect(result.rawValue).toBeGreaterThan(2000); expect(Math.round(result.rawValue)).toMatchSnapshot(); }); + + + it('override with simulated result fails a bad simulated TTI value', async () => { + const topLevelTasks = [ + {ts: 1000, duration: 1000}, + {ts: 3000, duration: 1000}, + {ts: 5000, duration: 1000}, + {ts: 9000, duration: 1000}, + {ts: 12000, duration: 1000}, + {ts: 14900, duration: 1000}, + ]; + const longTrace = createTestTrace({navigationStart: 0, traceEnd: 20000, topLevelTasks}); + + const artifacts = { + traces: {defaultPass: longTrace}, + devtoolsLogs: {defaultPass: devtoolsLog}, + }; + + const settings = {throttlingMethod: 'provided', throttling: {rttMs: 40, throughput: 100000}}; + const result = await FastPWAAudit.audit(artifacts, {settings, computedCache: new Map()}); + expect(result.displayValue).toContain('Interactive on simulated mobile network at %d\xa0s'); + expect(result.rawValue).toBeGreaterThan(10000); + }); });