|
| 1 | +/** |
| 2 | + * Copyright 2016 Google Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +const Audit = require('../../audits/cache-start-url.js'); |
| 17 | +const assert = require('assert'); |
| 18 | +const manifestSrc = JSON.stringify(require('../fixtures/manifest.json')); |
| 19 | +const manifestParser = require('../../lib/manifest-parser'); |
| 20 | +const Manifest = manifestParser(manifestSrc); |
| 21 | +const CacheContents = ['https://another.example.com/', 'https://example.com/']; |
| 22 | +const URL = 'https://example.com'; |
| 23 | +const AltURL = 'https://example.com/?utm_source=http203'; |
| 24 | + |
| 25 | +/* global describe, it*/ |
| 26 | + |
| 27 | +describe('Cache: start_url audit', () => { |
| 28 | + it('fails when no manifest present', () => { |
| 29 | + return assert.equal(Audit.audit({Manifest: { |
| 30 | + value: undefined |
| 31 | + }}).rawValue, false); |
| 32 | + }); |
| 33 | + |
| 34 | + it('fails when an empty manifest is present', () => { |
| 35 | + return assert.equal(Audit.audit({Manifest: {}}).rawValue, false); |
| 36 | + }); |
| 37 | + |
| 38 | + it('fails when no cache contents given', () => { |
| 39 | + return assert.equal(Audit.audit({Manifest, URL}).rawValue, false); |
| 40 | + }); |
| 41 | + |
| 42 | + it('fails when no URL given', () => { |
| 43 | + return assert.equal(Audit.audit({Manifest, CacheContents}).rawValue, false); |
| 44 | + }); |
| 45 | + |
| 46 | + // Need to disable camelcase check for dealing with short_name. |
| 47 | + /* eslint-disable camelcase */ |
| 48 | + it('fails when a manifest contains no start_url', () => { |
| 49 | + const inputs = { |
| 50 | + Manifest: { |
| 51 | + start_url: null |
| 52 | + } |
| 53 | + }; |
| 54 | + |
| 55 | + return assert.equal(Audit.audit(inputs).rawValue, false); |
| 56 | + }); |
| 57 | + |
| 58 | + /* eslint-enable camelcase */ |
| 59 | + |
| 60 | + it('succeeds when given a manifest with a start_url, cache contents, and a URL', () => { |
| 61 | + return assert.equal(Audit.audit({ |
| 62 | + Manifest, |
| 63 | + CacheContents, |
| 64 | + URL |
| 65 | + }).rawValue, true); |
| 66 | + }); |
| 67 | + |
| 68 | + it('handles URLs with utm params', () => { |
| 69 | + return assert.equal(Audit.audit({ |
| 70 | + Manifest, |
| 71 | + CacheContents, |
| 72 | + URL: AltURL |
| 73 | + }).rawValue, true); |
| 74 | + }); |
| 75 | +}); |
0 commit comments