Skip to content

Commit

Permalink
Offline audit: add warning if initial url != final url
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Mar 27, 2017
1 parent e822cbe commit f53654e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
12 changes: 10 additions & 2 deletions lighthouse-core/audits/works-offline.js
Expand Up @@ -30,7 +30,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']
};
}

Expand All @@ -39,8 +39,16 @@ class WorksOffline extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
let debugString;
if (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
};
}
}
Expand Down
30 changes: 25 additions & 5 deletions lighthouse-core/test/audits/works-offline-test.js
Expand Up @@ -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}
});

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'}
});

return assert.equal(output.rawValue, true);
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);
});
});

0 comments on commit f53654e

Please sign in to comment.