diff --git a/lighthouse-core/audits/works-offline.js b/lighthouse-core/audits/works-offline.js index ef8057e62f..a3113b0477 100644 --- a/lighthouse-core/audits/works-offline.js +++ b/lighthouse-core/audits/works-offline.js @@ -16,6 +16,7 @@ */ 'use strict'; +const URL = require('../lib/url-shim'); const Audit = require('./audit'); class WorksOffline extends Audit { @@ -30,7 +31,7 @@ class WorksOffline extends Audit { helpText: 'If you\'re building a Progressive Web App, consider using a service worker so ' + 'that your app can work offline. ' + '[Learn more](https://developers.google.com/web/tools/lighthouse/audits/http-200-when-offline).', - requiredArtifacts: ['Offline'] + requiredArtifacts: ['Offline', 'URL'] }; } @@ -39,8 +40,16 @@ class WorksOffline extends Audit { * @return {!AuditResult} */ static audit(artifacts) { + let debugString; + if (!URL.equalWithExcludedFragments(artifacts.URL.initialUrl, artifacts.URL.finalUrl)) { + debugString = 'WARNING: You may be failing this check because your test URL ' + + `(${artifacts.URL.initialUrl}) was redirected to "${artifacts.URL.finalUrl}". ` + + 'Try testing the second URL directly.'; + } + return { - rawValue: artifacts.Offline === 200 + rawValue: artifacts.Offline === 200, + debugString }; } } diff --git a/lighthouse-core/test/audits/works-offline-test.js b/lighthouse-core/test/audits/works-offline-test.js index 08737f289e..cf633c7c63 100644 --- a/lighthouse-core/test/audits/works-offline-test.js +++ b/lighthouse-core/test/audits/works-offline-test.js @@ -18,18 +18,38 @@ const Audit = require('../../audits/works-offline.js'); const assert = require('assert'); -/* global describe, it*/ +/* eslint-env mocha */ + +const URL = 'https://www.chromestatus.com'; describe('Offline: works-offline audit', () => { it('correctly audits a 200 code', () => { - const output = Audit.audit({Offline: 200}); + const output = Audit.audit({ + Offline: 200, + URL: {initialUrl: URL, finalUrl: URL} + }); - return assert.equal(output.rawValue, true); + assert.equal(output.rawValue, true); + assert.ok(!output.debugString); + }); + + it('warns if initial url does not match final url', () => { + const output = Audit.audit({ + Offline: 200, + URL: {initialUrl: URL, finalUrl: `${URL}/features`} + }); + + assert.equal(output.rawValue, true); + assert.ok(output.debugString); }); it('correctly audits a non-200 code', () => { - const output = Audit.audit({Offline: 203}); + const output = Audit.audit({ + Offline: 203, + URL: {initialUrl: URL, finalUrl: URL} + }); - return assert.equal(output.rawValue, false); + assert.equal(output.rawValue, false); + assert.ok(!output.debugString); }); });