Skip to content

Commit

Permalink
Remove the PersistentCache functionality (#949)
Browse files Browse the repository at this point in the history
* Initial pass at PersistentCache

* Drop test coverage

* Change test
  • Loading branch information
kieran-sf authored Jan 30, 2023
1 parent 40e2c18 commit 48cf774
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 1,211 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ coverage/
packages/*/out
packages/*/docs/www
lerna-debug.log
.idea/
.idea/
.vscode/
25 changes: 10 additions & 15 deletions packages/pwa-kit-dev/src/ssr/server/build-dev-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ describe('DevServer persistent caching support', () => {
route = null
})

test('Caching of compressed responses', () => {
test('No caching of compressed responses', () => {
// ADN-118 reported that a cached response was correctly sent
// the first time, but was corrupted the second time. This
// test is specific to that issue.
Expand All @@ -578,12 +578,12 @@ describe('DevServer persistent caching support', () => {
namespace
})
)
.then((entry) => expect(entry.found).toBe(true))
.then((entry) => expect(entry.found).toBe(false))
.then(() => request(app).get(url))
.then((res) => app._requestMonitor._waitForResponses().then(() => res))
.then((res) => {
expect(res.status).toEqual(200)
expect(res.headers['x-mobify-from-cache']).toEqual('true')
expect(res.headers['x-mobify-from-cache']).toEqual('false')
expect(res.headers['content-encoding']).toEqual('gzip')
expect(res.text).toEqual(expected)
})
Expand All @@ -599,20 +599,15 @@ describe('DevServer persistent caching support', () => {
expect(res.status).toEqual(200)
expect(res.headers['x-mobify-from-cache']).toEqual('false')
expect(res.headers['content-encoding']).toEqual('gzip')
return res
})
.then((res) =>
app.applicationCache
.get({
key: keyFromURL(url),
namespace
})
.then((entry) => ({res, entry}))
.then(() =>
app.applicationCache.get({
key: keyFromURL(url),
namespace
})
)
.then(({res, entry}) => {
expect(entry.found).toBe(true)
const uncompressed = zlib.gunzipSync(entry.data)
expect(uncompressed.toString()).toEqual(res.text)
.then((entry) => {
expect(entry.found).toBe(false)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-runtime/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
...base,
coverageThreshold: {
global: {
branches: 92.4,
branches: 90,
functions: 87,
lines: 90,
statements: 90
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,7 @@ export const RemoteServerFactory = {

get applicationCache() {
if (!this._applicationCache) {
const bucket = process.env.CACHE_BUCKET_NAME
const useLocalCache = !(isRemote() || bucket)
this._applicationCache = new PersistentCache({
useLocalCache,
bucket,
prefix: process.env.CACHE_BUCKET_PREFIX,
sendMetric: app.sendMetric.bind(app)
})
this._applicationCache = new PersistentCache()
}
return this._applicationCache
}
Expand Down
59 changes: 45 additions & 14 deletions packages/pwa-kit-runtime/src/ssr/server/express.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ describe('SSRServer persistent caching', () => {
'x-rendered': 'true',
'content-type': 'text/html; charset=utf-8'
},
expectToBeCached: true,
expectToBeCached: false,
expectRenderCallCount: 1
},
{
Expand All @@ -682,7 +682,7 @@ describe('SSRServer persistent caching', () => {
'x-mobify-from-cache': 'false',
'content-type': 'image/png'
},
expectToBeCached: true,
expectToBeCached: false,
expectRenderCallCount: 1
},
{
Expand Down Expand Up @@ -713,18 +713,17 @@ describe('SSRServer persistent caching', () => {
url: '/cacheme/?type=html',
expectOk: true,
expectHeaders: {
'x-precached': 'true',
'x-mobify-from-cache': 'true',
'x-mobify-from-cache': 'false',
'content-type': 'text/html; charset=utf-8'
},
expectToBeCached: true,
expectRenderCallCount: 0,
expectToBeCached: false,
expectRenderCallCount: 1,
preCache: {
data: Buffer.from('<html>456</html>'),
metadata: {
status: 200,
headers: {
'x-precached': 'true',
'x-precached': 'false',
'content-type': 'text/html; charset=utf-8'
}
}
Expand All @@ -735,10 +734,10 @@ describe('SSRServer persistent caching', () => {
url: '/cacheme/?type=html',
expectOk: true,
expectHeaders: {
'x-mobify-from-cache': 'true'
'x-mobify-from-cache': 'false'
},
expectToBeCached: true,
expectRenderCallCount: 0,
expectToBeCached: false,
expectRenderCallCount: 1,
preCache: {
data: Buffer.from('<html>123</html>')
}
Expand All @@ -748,11 +747,10 @@ describe('SSRServer persistent caching', () => {
url: '/cacheme/?type=none',
expectOk: true,
expectHeaders: {
'x-precached': 'true',
'x-mobify-from-cache': 'true'
'x-mobify-from-cache': 'false'
},
expectToBeCached: true,
expectRenderCallCount: 0,
expectToBeCached: false,
expectRenderCallCount: 1,
preCache: {
data: undefined,
metadata: {
Expand Down Expand Up @@ -1029,3 +1027,36 @@ describe('getRuntime', () => {
expect(func()).toBe(MockDevServerFactory.name)
})
})

describe('DevServer middleware', () => {
afterEach(() => {
jest.restoreAllMocks()
})
test('_validateConfiguration protocol', () => {
let protocol = 'ftp'
let error = `Invalid local development server protocol ${protocol}. Valid protocols are http and https.`
expect(() => {
RemoteServerFactory._validateConfiguration(opts({protocol}))
}).toThrow(error)
})

test('_validateConfiguration sslFilePath', () => {
let sslFilePath = './does/not/exist'
let error =
'The sslFilePath option passed to the SSR server constructor ' +
'must be a path to an SSL certificate file ' +
'in PEM format, whose name ends with ".pem". ' +
'See the "cert" and "key" options on ' +
'https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options'
expect(() => {
RemoteServerFactory._validateConfiguration(opts({sslFilePath}))
}).toThrow(error)
})
test('_validateConfiguration strictSSL', () => {
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
RemoteServerFactory._validateConfiguration(opts({strictSSL: false}))
expect(warn.mock.calls).toEqual([
['The SSR Server has _strictSSL turned off for https requests']
])
})
})
Loading

0 comments on commit 48cf774

Please sign in to comment.