-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding error for caching POST requests, Adding tests for checkSWFileC…
…acheHeaders and allows no-store for valid headers (#1336)
- Loading branch information
Matt Gaunt
authored
Feb 28, 2018
1 parent
6bbe949
commit 17c38de
Showing
6 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
test/workbox-core/node/_private/test-checkSWFileCacheHeaders.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import {expect} from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
import {logger} from '../../../../packages/workbox-core/_private/logger.mjs'; | ||
import {checkSWFileCacheHeaders} from '../../../../packages/workbox-core/_private/checkSWFileCacheHeaders.mjs'; | ||
import {devOnly} from '../../../../infra/testing/env-it'; | ||
|
||
describe(`workbox-core cacheWrapper`, function() { | ||
let sandbox; | ||
|
||
before(function() { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(function() { | ||
sandbox.restore(); | ||
}); | ||
|
||
devOnly.it('should handle bad response', async () => { | ||
sandbox.stub(self, 'fetch').callsFake(async () => { | ||
return new Response('Not Found.', { | ||
status: 404, | ||
}); | ||
}); | ||
|
||
await checkSWFileCacheHeaders(); | ||
|
||
expect(logger.warn.callCount).to.equal(0); | ||
}); | ||
|
||
devOnly.it('should handle no cache-control header', async () => { | ||
sandbox.stub(self, 'fetch').callsFake(async () => { | ||
return new Response('OK'); | ||
}); | ||
|
||
await checkSWFileCacheHeaders(); | ||
|
||
expect(logger.warn.callCount).to.equal(0); | ||
}); | ||
|
||
devOnly.it('should log for bad cache-control header', async () => { | ||
sandbox.stub(self, 'fetch').callsFake(async () => { | ||
return new Response('OK', { | ||
headers: { | ||
'cache-control': 'max-age=2000', | ||
}, | ||
}); | ||
}); | ||
|
||
await checkSWFileCacheHeaders(); | ||
|
||
expect(logger.warn.callCount).to.equal(1); | ||
}); | ||
|
||
devOnly.it('should handle unexpected max-age cache-control header', async () => { | ||
sandbox.stub(self, 'fetch').callsFake(async () => { | ||
return new Response('OK', { | ||
headers: { | ||
'cache-control': 'max-age=abc', | ||
}, | ||
}); | ||
}); | ||
|
||
await checkSWFileCacheHeaders(); | ||
|
||
expect(logger.warn.callCount).to.equal(1); | ||
}); | ||
|
||
devOnly.it('should NOT log for max-age=0 cache-control header', async () => { | ||
sandbox.stub(self, 'fetch').callsFake(async () => { | ||
return new Response('OK', { | ||
headers: { | ||
'cache-control': 'max-age=0', | ||
}, | ||
}); | ||
}); | ||
|
||
await checkSWFileCacheHeaders(); | ||
|
||
expect(logger.warn.callCount).to.equal(0); | ||
}); | ||
|
||
devOnly.it('should NOT log for no-cache cache-control header', async () => { | ||
sandbox.stub(self, 'fetch').callsFake(async () => { | ||
return new Response('OK', { | ||
headers: { | ||
'cache-control': 'no-cache', | ||
}, | ||
}); | ||
}); | ||
|
||
await checkSWFileCacheHeaders(); | ||
|
||
expect(logger.warn.callCount).to.equal(0); | ||
}); | ||
|
||
devOnly.it('should NOT log for no-store cache-control header', async () => { | ||
sandbox.stub(self, 'fetch').callsFake(async () => { | ||
return new Response('OK', { | ||
headers: { | ||
'cache-control': 'no-cache', | ||
}, | ||
}); | ||
}); | ||
|
||
await checkSWFileCacheHeaders(); | ||
|
||
expect(logger.warn.callCount).to.equal(0); | ||
}); | ||
}); |