Skip to content

Commit 269b5a8

Browse files
committed
Fix exception on missing manifest start_url
1 parent 6663f6b commit 269b5a8

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lighthouse-core/audits/cache-start-url.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,23 @@ class CacheStartUrl extends Audit {
3939
*/
4040
static audit(artifacts) {
4141
let cacheHasStartUrl = false;
42+
const manifest = artifacts.Manifest && artifacts.Manifest.value;
43+
const cacheContents = artifacts.CacheContents;
44+
const baseURL = artifacts.URL;
4245

43-
if (!(artifacts.Manifest &&
44-
artifacts.Manifest.value &&
45-
artifacts.Manifest.value.start_url &&
46-
Array.isArray(artifacts.CacheContents) &&
47-
artifacts.URL)) {
46+
if (!(manifest && manifest.start_url && manifest.start_url.raw)) {
4847
return CacheStartUrl.generateAuditResult({
49-
rawValue: false
48+
rawValue: false,
49+
debugString: 'start_url not present in Manifest'
5050
});
5151
}
5252

53-
const manifest = artifacts.Manifest.value;
54-
const cacheContents = artifacts.CacheContents;
55-
const baseURL = artifacts.URL;
53+
if (!(Array.isArray(cacheContents) && artifacts.URL)) {
54+
return CacheStartUrl.generateAuditResult({
55+
rawValue: false,
56+
debugString: 'No cache or URL detected'
57+
});
58+
}
5659

5760
// Remove any UTM strings.
5861
const startURL = url.resolve(baseURL, manifest.start_url.raw).toString();

lighthouse-core/test/audits/cache-start-url.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ describe('Cache: start_url audit', () => {
4343
return assert.equal(Audit.audit({Manifest, CacheContents}).rawValue, false);
4444
});
4545

46+
// Need to disable camelcase check for dealing with short_name.
47+
/* eslint-disable camelcase */
48+
it('fails when a manifest contains no start_url', () => {
49+
const inputs = {
50+
Manifest: {
51+
52+
}
53+
};
54+
55+
return assert.equal(Audit.audit(inputs).rawValue, false);
56+
});
57+
4658
// Need to disable camelcase check for dealing with short_name.
4759
/* eslint-disable camelcase */
4860
it('fails when a manifest contains no start_url', () => {

0 commit comments

Comments
 (0)