1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/tests/helpers/caching-headers.js
Peter Bengtsson 8362602503 do rendering end-to-end tests with a real server (#26169)
* reinstate

* start server manually

* routing tests too

* skip more

* sleep more and fail if not 200

* use e2etest for content/ too

* feedbacked
2022-03-18 17:06:12 -04:00

15 lines
734 B
JavaScript

import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
export function checkCachingHeaders(res, defaultSurrogateKey = false, minMaxAge = 60 * 60) {
expect(res.headers['set-cookie']).toBeUndefined()
expect(res.headers['cache-control']).toContain('public')
const maxAgeSeconds = parseInt(res.header['cache-control'].match(/max-age=(\d+)/)[1], 10)
// Let's not be too specific in the tests, just as long as it's testing
// that it's a reasonably large number of seconds.
expect(maxAgeSeconds).toBeGreaterThanOrEqual(minMaxAge)
// Because it doesn't have have a unique URL
expect(res.headers['surrogate-key']).toBe(
defaultSurrogateKey ? SURROGATE_ENUMS.DEFAULT : SURROGATE_ENUMS.MANUAL
)
}