Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(webapp-install): simplify start_url warning when no SW is found #5067

Merged
merged 2 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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