From caa3f42989dae245d6ec14fdafe759909e49133d Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 14 Mar 2018 13:29:13 -0700 Subject: [PATCH] core: remove cache-start-url audit --- lighthouse-core/audits/cache-start-url.js | 66 ------------------- lighthouse-core/gather/gatherers/url.js | 2 - .../test/audits/cache-start-url-test.js | 45 ------------- 3 files changed, 113 deletions(-) delete mode 100644 lighthouse-core/audits/cache-start-url.js delete mode 100644 lighthouse-core/test/audits/cache-start-url-test.js diff --git a/lighthouse-core/audits/cache-start-url.js b/lighthouse-core/audits/cache-start-url.js deleted file mode 100644 index 38a520f0536d..000000000000 --- a/lighthouse-core/audits/cache-start-url.js +++ /dev/null @@ -1,66 +0,0 @@ -/** - * @license Copyright 2016 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -const Audit = require('./audit'); - -class CacheStartUrl extends Audit { - /** - * @return {!AuditMeta} - */ - static get meta() { - return { - name: 'cache-start-url', - description: 'Cache contains start_url from manifest (alpha)', - failureDescription: 'Cache does not contain start_url from manifest (alpha)', - requiredArtifacts: ['CacheContents', 'Manifest', 'URL'], - }; - } - - /** - * @param {!Artifacts} artifacts - * @return {!AuditResult} - */ - static audit(artifacts) { - if (!artifacts.Manifest || !artifacts.Manifest.value) { - // Page has no manifest or was invalid JSON. - return { - rawValue: false, - }; - } - - const manifest = artifacts.Manifest.value; - if (!(manifest.start_url && manifest.start_url.value)) { - return { - rawValue: false, - debugString: 'start_url not present in Manifest', - }; - } - - // Remove any UTM strings. - const startURL = manifest.start_url.value; - /** @const {string} */ - const altStartURL = startURL - .replace(/\?utm_([^=]*)=([^&]|$)*/, '') - .replace(/\?$/, ''); - - // Now find the start_url in the cacheContents. This test is less than ideal since the Service - // Worker can rewrite a request from the start URL to anything else in the cache, and so a TODO - // here would be to resolve this more completely by asking the service worker about the start - // URL. However that would also necessitate the cache contents gatherer relying on the manifest - // gather rather than being independent of it. - const cacheContents = artifacts.CacheContents; - const cacheHasStartUrl = cacheContents.find(req => { - return (startURL === req || altStartURL === req); - }); - - return { - rawValue: (cacheHasStartUrl !== undefined), - }; - } -} - -module.exports = CacheStartUrl; diff --git a/lighthouse-core/gather/gatherers/url.js b/lighthouse-core/gather/gatherers/url.js index fae83239e0d7..aa73351e5d91 100644 --- a/lighthouse-core/gather/gatherers/url.js +++ b/lighthouse-core/gather/gatherers/url.js @@ -9,8 +9,6 @@ const Gatherer = require('./gatherer'); class URL extends Gatherer { afterPass(options) { - // Used currently by cache-start-url audit, which wants to know if the start_url - // in the manifest is stored in the cache. // Instead of the originally inputted URL (options.initialUrl), we want the resolved // post-redirect URL (which is here at options.url) return { diff --git a/lighthouse-core/test/audits/cache-start-url-test.js b/lighthouse-core/test/audits/cache-start-url-test.js deleted file mode 100644 index 128bcc910d80..000000000000 --- a/lighthouse-core/test/audits/cache-start-url-test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @license Copyright 2016 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -const CacheStartUrlAudit = require('../../audits/cache-start-url.js'); -const assert = require('assert'); -const manifestSrc = JSON.stringify(require('../fixtures/manifest.json')); -const manifestParser = require('../../lib/manifest-parser'); -const CacheContents = ['https://another.example.com/', 'https://example.com/']; -const URL = 'https://example.com'; -const AltURL = 'https://example.com/?utm_source=http203'; -const exampleManifest = manifestParser(manifestSrc, URL, URL); - -/* eslint-env mocha */ - -describe('Cache: start_url audit', () => { - it('fails with no debugString if page had no manifest', () => { - const result = CacheStartUrlAudit.audit({ - Manifest: null, - CacheContents, - URL: {finalUrl: URL}, - }); - assert.strictEqual(result.rawValue, false); - assert.strictEqual(result.debugString, undefined); - }); - - it('succeeds when given a manifest with a start_url, cache contents, and a URL', () => { - return assert.equal(CacheStartUrlAudit.audit({ - Manifest: exampleManifest, - CacheContents, - URL: {finalUrl: URL}, - }).rawValue, true); - }); - - it('handles URLs with utm params', () => { - return assert.equal(CacheStartUrlAudit.audit({ - Manifest: exampleManifest, - CacheContents, - URL: {finalUrl: AltURL}, - }).rawValue, true); - }); -});