Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sw precaching #76

Merged
merged 20 commits into from
Dec 2, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ describe('Test RevisionedCacheManager', function() {
}).to.throw('null');
});

const VALID_PATH = '/__echo/date/example.txt';
const VALID_PATH_REL = '/__echo/date/example.txt';
const VALID_PATH_ABS = `${location.origin}${VALID_PATH_REL}`;
const VALID_REVISION = '1234';

const badPaths = [
Expand Down Expand Up @@ -93,12 +94,11 @@ describe('Test RevisionedCacheManager', function() {
badFileManifests.push([{path: badPath, revision: VALID_REVISION}]);
});
badRevisions.forEach((badRevision) => {
badFileManifests.push([{path: VALID_PATH, revision: badRevision}]);
badFileManifests.push([{path: VALID_PATH_REL, revision: badRevision}]);
});

badFileManifests.forEach((badFileManifest) => {
it(`should throw an errror for a page file manifest entry '${JSON.stringify(badFileManifest)}'`, function() {
console.log(JSON.stringify({revisionedFiles: badFileManifest}));
let caughtError;
try {
const revisionedCacheManager = new goog.precaching.RevisionedCacheManager();
Expand All @@ -114,4 +114,48 @@ describe('Test RevisionedCacheManager', function() {
caughtError.name.should.equal('invalid-file-manifest-entry');
});
});

const badCacheBusts = [
null,
'',
'1234sgdgh',
12345,
{},
[],
];

badCacheBusts.forEach((badCacheBust) => {
it(`should be able to handle bad cache input '${JSON.stringify(badCacheBust)}'`, function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it(testLabel), () => {?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocha has a weird thing with this.timeout and this.retries where it's bound to the function. Changing to arrow functions messes up the binding for these functions and using them throws an error that simply makes no sense compared to the actual problem / solution.

let caughtError;
try {
const revisionedCacheManager = new goog.precaching.RevisionedCacheManager();
revisionedCacheManager.cache({revisionedFiles: [
{path: VALID_PATH_REL, revision: VALID_REVISION, cacheBust: badCacheBust},
]});
} catch (err) {
caughtError = err;
}

if (!caughtError) {
throw new Error('Expected file manifest to cause an error.');
}

caughtError.name.should.equal('invalid-file-manifest-entry');
});
});

const goodManifestInputs = [
VALID_PATH_REL,
{path: VALID_PATH_REL, revision: VALID_REVISION},
{path: VALID_PATH_REL, revision: VALID_REVISION, cacheBust: true},
{path: VALID_PATH_REL, revision: VALID_REVISION, cacheBust: false},
VALID_PATH_ABS,
{path: VALID_PATH_ABS, revision: VALID_REVISION},
{path: VALID_PATH_ABS, revision: VALID_REVISION, cacheBust: true},
{path: VALID_PATH_ABS, revision: VALID_REVISION, cacheBust: false},
];
goodManifestInputs.forEach((goodInput) => {
const revisionedCacheManager = new goog.precaching.RevisionedCacheManager();
revisionedCacheManager.cache({revisionedFiles: [goodInput]});
});
});