Skip to content

Commit

Permalink
core(webapp-install): simplify start_url warning when no SW is found (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet authored and kdzwinel committed Aug 16, 2018
1 parent d04c839 commit 07945b6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
55 changes: 38 additions & 17 deletions lighthouse-core/audits/webapp-install-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ class WebappInstallBanner extends MultiCheckAudit {
};
}

static assessManifest(artifacts, result) {
const {manifestValues, failures} = result;
static assessManifest(manifestValues) {
if (manifestValues.isParseFailure) {
failures.push(manifestValues.parseFailureReason);
return;
return [manifestValues.parseFailureReason];
}

const failures = [];
const bannerCheckIds = [
'hasName',
'hasShortName',
Expand All @@ -65,40 +64,62 @@ class WebappInstallBanner extends MultiCheckAudit {
failures.push(item.failureText);
}
});

return failures;
}


static assessServiceWorker(artifacts, result) {
static assessServiceWorker(artifacts) {
const failures = [];
const hasServiceWorker = SWAudit.audit(artifacts).rawValue;
if (!hasServiceWorker) {
result.failures.push('Site does not register a service worker');
failures.push('Site does not register a service worker');
}

return failures;
}

static assessOfflineStartUrl(artifacts, result) {
static assessOfflineStartUrl(artifacts) {
const failures = [];
const warnings = [];
const hasOfflineStartUrl = artifacts.StartUrl.statusCode === 200;

if (!hasOfflineStartUrl) {
result.failures.push('Service worker does not successfully serve the manifest\'s start_url');
if (artifacts.StartUrl.debugString) result.failures.push(artifacts.StartUrl.debugString);
failures.push('Service worker does not successfully serve the manifest\'s start_url');
if (artifacts.StartUrl.debugString) {
failures.push(artifacts.StartUrl.debugString);
}
}

if (artifacts.StartUrl.debugString) {
result.warnings.push(artifacts.StartUrl.debugString);
warnings.push(artifacts.StartUrl.debugString);
}

return {failures, warnings};
}

static audit_(artifacts) {
const failures = [];
const warnings = [];
let offlineFailures = [];
let offlineWarnings = [];

return artifacts.requestManifestValues(artifacts.Manifest).then(manifestValues => {
const result = {warnings, failures, manifestValues};
WebappInstallBanner.assessManifest(artifacts, result);
WebappInstallBanner.assessServiceWorker(artifacts, result);
WebappInstallBanner.assessOfflineStartUrl(artifacts, result);
const manifestFailures = WebappInstallBanner.assessManifest(manifestValues);
const swFailures = WebappInstallBanner.assessServiceWorker(artifacts);
if (!swFailures.length) {
const {failures, warnings} = WebappInstallBanner.assessOfflineStartUrl(artifacts);
offlineFailures = failures;
offlineWarnings = warnings;
}

return result;
return {
warnings: offlineWarnings,
failures: [
...manifestFailures,
...swFailures,
...offlineFailures,
],
manifestValues,
};
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/test/audits/webapp-install-banner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ describe('PWA: webapp install banner audit', () => {
assert.strictEqual(result.rawValue, false);
assert.ok(result.debugString.includes('service worker'), result.debugString);
const failures = result.extendedInfo.value.failures;
// start url will be -1 as well so failures will be 2
assert.strictEqual(failures.length, 2, failures);
assert.strictEqual(failures.length, 1, failures);
});
});

Expand Down
10 changes: 3 additions & 7 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,17 +651,13 @@
"score": 0,
"displayValue": "",
"rawValue": false,
"debugString": "Failures: No manifest was fetched, Site does not register a service worker, Service worker does not successfully serve the manifest's start_url, No start URL to fetch: No usable web app manifest found on page http://localhost:10200/dobetterweb/dbw_tester.html.",
"debugString": "Failures: No manifest was fetched, Site does not register a service worker.",
"extendedInfo": {
"value": {
"warnings": [
"No start URL to fetch: No usable web app manifest found on page http://localhost:10200/dobetterweb/dbw_tester.html"
],
"warnings": [],
"failures": [
"No manifest was fetched",
"Site does not register a service worker",
"Service worker does not successfully serve the manifest's start_url",
"No start URL to fetch: No usable web app manifest found on page http://localhost:10200/dobetterweb/dbw_tester.html"
"Site does not register a service worker"
],
"manifestValues": {
"isParseFailure": true,
Expand Down

0 comments on commit 07945b6

Please sign in to comment.