|
| 1 | +import { nextTestSetup } from 'e2e-utils' |
| 2 | + |
| 3 | +describe('custom-cache-control', () => { |
| 4 | + const { next, isNextDev, isNextDeploy } = nextTestSetup({ |
| 5 | + files: __dirname, |
| 6 | + }) |
| 7 | + |
| 8 | + if (isNextDeploy) { |
| 9 | + // customizing these headers won't apply on environments |
| 10 | + // where headers are applied outside of the Next.js server |
| 11 | + it('should skip for deploy', () => {}) |
| 12 | + return |
| 13 | + } |
| 14 | + |
| 15 | + it('should have custom cache-control for app-ssg prerendered', async () => { |
| 16 | + const res = await next.fetch('/app-ssg/first') |
| 17 | + expect(res.headers.get('cache-control')).toBe( |
| 18 | + isNextDev ? 'no-store, must-revalidate' : 's-maxage=30' |
| 19 | + ) |
| 20 | + }) |
| 21 | + |
| 22 | + it('should have custom cache-control for app-ssg lazy', async () => { |
| 23 | + const res = await next.fetch('/app-ssg/lazy') |
| 24 | + expect(res.headers.get('cache-control')).toBe( |
| 25 | + isNextDev ? 'no-store, must-revalidate' : 's-maxage=31' |
| 26 | + ) |
| 27 | + }) |
| 28 | + ;(process.env.__NEXT_EXPERIMENTAL_PPR ? it.skip : it)( |
| 29 | + 'should have default cache-control for app-ssg another', |
| 30 | + async () => { |
| 31 | + const res = await next.fetch('/app-ssg/another') |
| 32 | + // eslint-disable-next-line jest/no-standalone-expect |
| 33 | + expect(res.headers.get('cache-control')).toBe( |
| 34 | + isNextDev |
| 35 | + ? 'no-store, must-revalidate' |
| 36 | + : 's-maxage=120, stale-while-revalidate' |
| 37 | + ) |
| 38 | + } |
| 39 | + ) |
| 40 | + |
| 41 | + it('should have custom cache-control for app-ssr', async () => { |
| 42 | + const res = await next.fetch('/app-ssr') |
| 43 | + expect(res.headers.get('cache-control')).toBe( |
| 44 | + isNextDev ? 'no-store, must-revalidate' : 's-maxage=32' |
| 45 | + ) |
| 46 | + }) |
| 47 | + |
| 48 | + it('should have custom cache-control for auto static page', async () => { |
| 49 | + const res = await next.fetch('/pages-auto-static') |
| 50 | + expect(res.headers.get('cache-control')).toBe( |
| 51 | + isNextDev ? 'no-store, must-revalidate' : 's-maxage=33' |
| 52 | + ) |
| 53 | + }) |
| 54 | + |
| 55 | + it('should have custom cache-control for pages-ssg prerendered', async () => { |
| 56 | + const res = await next.fetch('/pages-ssg/first') |
| 57 | + expect(res.headers.get('cache-control')).toBe( |
| 58 | + isNextDev ? 'no-store, must-revalidate' : 's-maxage=34' |
| 59 | + ) |
| 60 | + }) |
| 61 | + |
| 62 | + it('should have custom cache-control for pages-ssg lazy', async () => { |
| 63 | + const res = await next.fetch('/pages-ssg/lazy') |
| 64 | + expect(res.headers.get('cache-control')).toBe( |
| 65 | + isNextDev ? 'no-store, must-revalidate' : 's-maxage=35' |
| 66 | + ) |
| 67 | + }) |
| 68 | + |
| 69 | + it('should have default cache-control for pages-ssg another', async () => { |
| 70 | + const res = await next.fetch('/pages-ssg/another') |
| 71 | + expect(res.headers.get('cache-control')).toBe( |
| 72 | + isNextDev |
| 73 | + ? 'no-store, must-revalidate' |
| 74 | + : 's-maxage=120, stale-while-revalidate' |
| 75 | + ) |
| 76 | + }) |
| 77 | + |
| 78 | + it('should have default cache-control for pages-ssr', async () => { |
| 79 | + const res = await next.fetch('/pages-ssr') |
| 80 | + expect(res.headers.get('cache-control')).toBe( |
| 81 | + isNextDev ? 'no-store, must-revalidate' : 's-maxage=36' |
| 82 | + ) |
| 83 | + }) |
| 84 | +}) |
0 commit comments