-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* @license Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Audit = require('./audit'); | ||
const TTIMetric = require('./time-to-interactive'); | ||
const Formatter = require('../formatters/formatter'); | ||
|
||
// Maximum TTI to be considered "fast" for PWA baseline checklist | ||
// https://developers.google.com/web/progressive-web-apps/checklist | ||
const MAXIMUM_TTI = 10 * 1000; | ||
|
||
class LoadFastEnough4Pwa extends Audit { | ||
/** | ||
* @return {!AuditMeta} | ||
*/ | ||
static get meta() { | ||
return { | ||
category: 'PWA', | ||
name: 'load-fast-enough-for-pwa', | ||
description: 'Page load is fast enough on 3G', | ||
helpText: 'Satisfied if the _Time To Interactive_ duration is shorter than _10 seconds_, as defined by the [PWA Baseline Checklist](https://developers.google.com/web/progressive-web-apps/checklist).', | ||
requiredArtifacts: ['traces'] | ||
}; | ||
} | ||
|
||
/** | ||
* @param {!Artifacts} artifacts | ||
* @return {!AuditResult} | ||
*/ | ||
static audit(artifacts) { | ||
return TTIMetric.audit(artifacts).then(ttiResult => { | ||
const timeToInteractive = ttiResult.extendedInfo.value.timings.timeToInteractive; | ||
const isFast = timeToInteractive < MAXIMUM_TTI; | ||
|
||
const extendedInfo = { | ||
formatter: Formatter.SUPPORTED_FORMATS.NULL, | ||
value: {timeToInteractive} | ||
}; | ||
|
||
if (!isFast) { | ||
return LoadFastEnough4Pwa.generateAuditResult({ | ||
rawValue: false, | ||
debugString: `Under mobile conditions, the TTI was at ${ttiResult.displayValue}. ` + | ||
'More details in "Performance" section.', | ||
extendedInfo | ||
}); | ||
} | ||
|
||
return LoadFastEnough4Pwa.generateAuditResult({ | ||
rawValue: true, | ||
extendedInfo | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = LoadFastEnough4Pwa; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
lighthouse-core/test/audits/load-fast-enough-for-pwa-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @license Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const FastPWAAudit = require('../../audits/load-fast-enough-for-pwa'); | ||
const TTIAudit = require('../../audits/time-to-interactive'); | ||
const Audit = require('../../audits/audit.js'); | ||
const assert = require('assert'); | ||
const traceEvents = require('../fixtures/traces/progressive-app.json'); | ||
|
||
const GatherRunner = require('../../gather/gather-runner.js'); | ||
const computedArtifacts = GatherRunner.instantiateComputedArtifacts(); | ||
|
||
function generateArtifactsWithTrace(trace) { | ||
return Object.assign(computedArtifacts, { | ||
traces: { | ||
[Audit.DEFAULT_PASS]: {traceEvents: Array.isArray(trace) ? trace : trace.traceEvents} | ||
} | ||
}); | ||
} | ||
|
||
/* eslint-env mocha */ | ||
describe('PWA: load-fast-enough-for-pwa audit', () => { | ||
it('returns boolean based on TTI value', () => { | ||
return FastPWAAudit.audit(generateArtifactsWithTrace(traceEvents)).then(result => { | ||
assert.equal(result.rawValue, true, 'fixture trace is not passing audit'); | ||
}).catch(err => { | ||
assert.ok(false, err); | ||
}); | ||
}); | ||
|
||
it('fails a bad TTI value', () => { | ||
// mock a return for the TTI Audit | ||
const origTTI = TTIAudit.audit; | ||
const mockTTIResult = {extendedInfo: {value: {timings: {timeToInteractive: 15000}}}}; | ||
TTIAudit.audit = _ => Promise.resolve(mockTTIResult); | ||
|
||
return FastPWAAudit.audit(generateArtifactsWithTrace(traceEvents)).then(result => { | ||
assert.equal(result.rawValue, false, 'not failing a long TTI value'); | ||
TTIAudit.audit = origTTI; | ||
}).catch(err => { | ||
assert.ok(false, err); | ||
}); | ||
}); | ||
}); |