Skip to content

Commit 7d53ae7

Browse files
committed
test: case for invalidating dynamic 404 pages
1 parent 0179822 commit 7d53ae7

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

tests/e2e/dynamic-cms.test.ts

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

tests/fixtures/dynamic-cms/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This fixture is meant to emulate dynamic content responses of a CMS-backed next site
1+
This fixture is meant to emulate dynamic content responses of a CMS-backed next site

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)