Skip to content

Commit

Permalink
add more cache header tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 25, 2022
1 parent 99e62b6 commit b6c251f
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions test/e2e/prerender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1906,24 +1906,28 @@ describe('Prerender', () => {

if (!(global as any).isNextDev) {
it('should handle manual revalidate for fallback: blocking', async () => {
const html = await renderViaHTTP(
const res = await fetchViaHTTP(
next.url,
'/blocking-fallback/test-manual-1'
)
const html = await res.text()
const $ = cheerio.load(html)
const initialTime = $('#time').text()
expect(res.headers.get('x-nextjs-cache')).toMatch(/MISS/)

expect($('p').text()).toMatch(/Post:.*?test-manual-1/)

const html2 = await renderViaHTTP(
const res2 = await fetchViaHTTP(
next.url,
'/blocking-fallback/test-manual-1'
)
const html2 = await res2.text()
const $2 = cheerio.load(html2)
expect(res2.headers.get('x-nextjs-cache')).toMatch(/(HIT|STALE)/)

expect(initialTime).toBe($2('#time').text())

const res = await fetchViaHTTP(
const res3 = await fetchViaHTTP(
next.url,
'/api/manual-revalidate',
{
Expand All @@ -1932,16 +1936,18 @@ describe('Prerender', () => {
{ redirect: 'manual' }
)

expect(res.status).toBe(200)
const revalidateData = await res.json()
expect(res2.status).toBe(200)
const revalidateData = await res3.json()
expect(revalidateData.revalidated).toBe(true)

const html4 = await renderViaHTTP(
const res4 = await fetchViaHTTP(
next.url,
'/blocking-fallback/test-manual-1'
)
const html4 = await res4.text()
const $4 = cheerio.load(html4)
expect($4('#time').text()).not.toBe(initialTime)
expect(res4.headers.get('x-nextjs-cache')).toMatch(/(HIT|STALE)/)
})

it('should manual revalidate for revalidate: false', async () => {
Expand Down Expand Up @@ -1984,12 +1990,14 @@ describe('Prerender', () => {
})

it('should manual revalidate that returns notFound: true', async () => {
const html = await renderViaHTTP(
const res = await fetchViaHTTP(
next.url,
'/blocking-fallback-once/404-on-manual-revalidate'
)
const html = await res.text()
const $ = cheerio.load(html)
const initialTime = $('#time').text()
expect(res.headers.get('x-nextjs-cache')).toBe('HIT')

expect($('p').text()).toMatch(/Post:.*?404-on-manual-revalidate/)

Expand All @@ -2001,24 +2009,25 @@ describe('Prerender', () => {

expect(initialTime).toBe($2('#time').text())

const res = await fetchViaHTTP(
const res2 = await fetchViaHTTP(
next.url,
'/api/manual-revalidate',
{
pathname: '/blocking-fallback-once/404-on-manual-revalidate',
},
{ redirect: 'manual' }
)
expect(res.status).toBe(200)
const revalidateData = await res.json()
expect(res2.status).toBe(200)
const revalidateData = await res2.json()
expect(revalidateData.revalidated).toBe(true)

const res2 = await fetchViaHTTP(
const res3 = await fetchViaHTTP(
next.url,
'/blocking-fallback-once/404-on-manual-revalidate'
)
expect(res2.status).toBe(404)
expect(await res2.text()).toContain('This page could not be found')
expect(res3.status).toBe(404)
expect(await res3.text()).toContain('This page could not be found')
expect(res3.headers.get('x-nextjs-cache')).toBe('HIT')
})

it('should handle manual revalidate for fallback: false', async () => {
Expand Down

0 comments on commit b6c251f

Please sign in to comment.