Skip to content

Commit

Permalink
core(installable-manifest): expose app manifest url (GoogleChrome#11330)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianaixba authored and George Martin committed Sep 1, 2020
1 parent 306b628 commit 349fe91
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
Expand Up @@ -116,7 +116,7 @@ module.exports = [
},
'installable-manifest': {
score: 1,
details: {items: [pwaDetailsExpectations]},
details: {items: [{...pwaDetailsExpectations, manifestUrl: 'https://caltrainschedule.io/manifest.json'}]},
},
'splash-screen': {
score: 1,
Expand Down
5 changes: 4 additions & 1 deletion lighthouse-core/audits/installable-manifest.js
Expand Up @@ -89,17 +89,20 @@ class InstallableManifest extends MultiCheckAudit {
/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {Promise<{failures: Array<string>, manifestValues: LH.Artifacts.ManifestValues}>}
* @return {Promise<{failures: Array<string>, manifestValues: LH.Artifacts.ManifestValues, manifestUrl: string | null}>}
*/
static async audit_(artifacts, context) {
const manifestValues = await ManifestValues.request(artifacts, context);
const manifestFailures = InstallableManifest.assessManifest(manifestValues);

const manifestUrl = artifacts.WebAppManifest ? artifacts.WebAppManifest.url : null;

return {
failures: [
...manifestFailures,
],
manifestValues,
manifestUrl,
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions lighthouse-core/lib/manifest-parser.js
Expand Up @@ -472,6 +472,7 @@ function parse(string, manifestUrl, documentUrl) {
raw: string,
value: undefined,
warning: 'ERROR: file isn\'t valid JSON: ' + e,
url: manifestUrl,
};
}

Expand Down Expand Up @@ -505,6 +506,7 @@ function parse(string, manifestUrl, documentUrl) {
raw: string,
value: manifest,
warning: manifestUrlWarning,
url: manifestUrl,
};
}

Expand Down
10 changes: 10 additions & 0 deletions lighthouse-core/test/audits/installable-manifest-test.js
Expand Up @@ -44,6 +44,16 @@ describe('PWA: webapp install banner audit', () => {
});
});

it('passes when manifest url matches', () => {
const artifacts = generateMockArtifacts();
const context = generateMockAuditContext();

return InstallableManifestAudit.audit(artifacts, context).then(result => {
assert.strictEqual(artifacts.WebAppManifest.url, EXAMPLE_MANIFEST_URL);
assert.strictEqual(result.details.items[0].manifestUrl, EXAMPLE_MANIFEST_URL);
});
});

it('fails with a non-parsable manifest', () => {
const artifacts = generateMockArtifacts('{,:}');
const context = generateMockAuditContext();
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/test/gather/gather-runner-test.js
Expand Up @@ -1803,6 +1803,7 @@ describe('GatherRunner', function() {
name: {value: 'App', raw: 'App'},
start_url: {value: passContext.url, raw: undefined},
});
expect(result && result.url).toMatch(MANIFEST_URL);
});
});
});
1 change: 1 addition & 0 deletions lighthouse-core/test/results/sample_v2.json
Expand Up @@ -528,6 +528,7 @@
"failures": [
"No manifest was fetched"
],
"manifestUrl": null,
"isParseFailure": true,
"parseFailureReason": "No manifest was fetched"
}
Expand Down

0 comments on commit 349fe91

Please sign in to comment.