Skip to content

Commit

Permalink
Added multiple output strings for pwa load audit.
Browse files Browse the repository at this point in the history
  • Loading branch information
exterkamp committed Oct 16, 2018
1 parent 72a0932 commit 31a2639
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lighthouse-core/audits/load-fast-enough-for-pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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.';
Expand Down
23 changes: 23 additions & 0 deletions lighthouse-core/test/audits/load-fast-enough-for-pwa-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 31a2639

Please sign in to comment.