Skip to content

Commit

Permalink
Fix exception on missing manifest start_url
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Aug 4, 2016
1 parent 6663f6b commit 269b5a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lighthouse-core/audits/cache-start-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@ class CacheStartUrl extends Audit {
*/
static audit(artifacts) {
let cacheHasStartUrl = false;
const manifest = artifacts.Manifest && artifacts.Manifest.value;
const cacheContents = artifacts.CacheContents;
const baseURL = artifacts.URL;

if (!(artifacts.Manifest &&
artifacts.Manifest.value &&
artifacts.Manifest.value.start_url &&
Array.isArray(artifacts.CacheContents) &&
artifacts.URL)) {
if (!(manifest && manifest.start_url && manifest.start_url.raw)) {
return CacheStartUrl.generateAuditResult({
rawValue: false
rawValue: false,
debugString: 'start_url not present in Manifest'
});
}

const manifest = artifacts.Manifest.value;
const cacheContents = artifacts.CacheContents;
const baseURL = artifacts.URL;
if (!(Array.isArray(cacheContents) && artifacts.URL)) {
return CacheStartUrl.generateAuditResult({
rawValue: false,
debugString: 'No cache or URL detected'
});
}

// Remove any UTM strings.
const startURL = url.resolve(baseURL, manifest.start_url.raw).toString();
Expand Down
12 changes: 12 additions & 0 deletions lighthouse-core/test/audits/cache-start-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ describe('Cache: start_url audit', () => {
return assert.equal(Audit.audit({Manifest, CacheContents}).rawValue, false);
});

// Need to disable camelcase check for dealing with short_name.
/* eslint-disable camelcase */
it('fails when a manifest contains no start_url', () => {
const inputs = {
Manifest: {

}
};

return assert.equal(Audit.audit(inputs).rawValue, false);
});

// Need to disable camelcase check for dealing with short_name.
/* eslint-disable camelcase */
it('fails when a manifest contains no start_url', () => {
Expand Down

0 comments on commit 269b5a8

Please sign in to comment.