Skip to content

Commit 4689d0b

Browse files
committed
test: case for invalidating dynamic 404 pages
1 parent 1e37776 commit 4689d0b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/e2e/dynamic-cms.test.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { expect } from '@playwright/test'
2+
import { test } from '../utils/playwright-helpers.js'
3+
4+
test.describe('Dynamic CMS', () => {
5+
test('Invalidates 404 pages from durable cache', async ({ page, dynamicCms }) => {
6+
7+
// 1. Verify the status and headers of the dynamic page
8+
const response1 = await page.goto(new URL('/content/blog', dynamicCms.url).href)
9+
const headers1 = response1?.headers() || {}
10+
11+
expect(response1?.status()).toEqual(404)
12+
expect(headers1['cache-control']).toEqual('public,max-age=0,must-revalidate')
13+
expect(headers1['cache-status']).toEqual('"Next.js"; fwd=miss, "Netlify Durable"; fwd=uri-miss; stored, "Netlify Edge"; fwd=miss')
14+
expect(headers1['netlify-cache-tag']).toEqual('_n_t_/content/blog')
15+
expect(headers1['netlify-cdn-cache-control']).toEqual('s-maxage=31536000, durable')
16+
17+
// 2. Publish the blob, revalidate the dynamic page, and wait to regenerate
18+
await page.goto(new URL('/cms/publish', dynamicCms.url).href)
19+
await page.goto(new URL('/api/revalidate?path=/content/blog', dynamicCms.url).href)
20+
await page.waitForTimeout(1000)
21+
22+
// 3. Verify the status and headers of the dynamic page
23+
const response2 = await page.goto(new URL('/content/blog', dynamicCms.url).href)
24+
const headers2 = response2?.headers() || {}
25+
26+
expect(response2?.status()).toEqual(200)
27+
expect(headers2['cache-control']).toEqual('public,max-age=0,must-revalidate')
28+
expect(headers2['cache-status']).toMatch(
29+
/"Next.js"; hit, "Netlify Durable"; fwd=stale; ttl=[0-9]+; stored, "Netlify Edge"; fwd=stale/
30+
)
31+
expect(headers2['netlify-cache-tag']).toEqual('_n_t_/content/blog')
32+
expect(headers2['netlify-cdn-cache-control']).toEqual('s-maxage=31536000, durable')
33+
34+
// 4. Unpublish the blob, revalidate the dynamic page, and wait to regenerate
35+
await page.goto(new URL('/cms/unpublish', dynamicCms.url).href)
36+
await page.goto(new URL('/api/revalidate?path=/content/blog', dynamicCms.url).href)
37+
await page.waitForTimeout(1000)
38+
39+
// 5. Verify the status and headers of the dynamic page
40+
const response3 = await page.goto(new URL('/content/blog', dynamicCms.url).href)
41+
const headers3 = response3?.headers() || {}
42+
43+
expect(response3?.status()).toEqual(404)
44+
expect(headers3['cache-control']).toEqual('public,max-age=0,must-revalidate')
45+
expect(headers3['cache-status']).toMatch(
46+
/"Next.js"; fwd=miss, "Netlify Durable"; fwd=stale; ttl=[0-9]+; stored, "Netlify Edge"; fwd=stale/
47+
)
48+
expect(headers3['netlify-cache-tag']).toEqual('_n_t_/content/blog')
49+
expect(headers3['netlify-cdn-cache-control']).toEqual('s-maxage=31536000, durable')
50+
})
51+
})

tests/utils/create-e2e-fixture.ts

+1
Original file line numberDiff line numberDiff line change
@@ -440,5 +440,6 @@ export const fixtureFactories = {
440440
publishDirectory: 'apps/site/.next',
441441
smoke: true,
442442
}),
443+
dynamicCms: () => createE2EFixture('dynamic-cms'),
443444
after: () => createE2EFixture('after'),
444445
}

0 commit comments

Comments
 (0)