Offline audit: add warning if initial url != final url (#1919)

* Offline audit: add warning if initial url != final url

* feedback
This commit is contained in:
Eric Bidelman 2017-03-28 10:58:25 -07:00 коммит произвёл GitHub
Родитель 0386598fe8
Коммит 4e08d0f1a4
2 изменённых файлов: 36 добавлений и 7 удалений

Просмотреть файл

@ -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
};
}
}

Просмотреть файл

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