Skip to content

Commit 554010c

Browse files
committed
test: repeat publish and publish for more confidence
1 parent b4f04e3 commit 554010c

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

tests/e2e/dynamic-cms.test.ts

+40-37
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,45 @@ test.describe('Dynamic CMS', () => {
1717
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/,
1818
)
1919

20-
// 2. Publish the blob, revalidate the dynamic page, and wait to regenerate
21-
await page.goto(new URL('/cms/publish', dynamicCms.url).href)
22-
await page.goto(new URL('/api/revalidate?path=/content/blog', dynamicCms.url).href)
23-
await page.waitForTimeout(1000)
24-
25-
// 3. Verify the status and headers of the dynamic page
26-
const response2 = await page.goto(new URL('/content/blog', dynamicCms.url).href)
27-
const headers2 = response2?.headers() || {}
28-
29-
expect(response2?.status()).toEqual(200)
30-
expect(headers2['cache-control']).toEqual('public,max-age=0,must-revalidate')
31-
expect(headers2['cache-status']).toMatch(
32-
/"Next.js"; hit, "Netlify Durable"; fwd=stale; ttl=[0-9]+; stored, "Netlify Edge"; fwd=(stale|miss)/,
33-
)
34-
expect(headers2['netlify-cache-tag']).toEqual('_n_t_/content/blog')
35-
expect(headers2['netlify-cdn-cache-control']).toMatch(
36-
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/,
37-
)
38-
39-
// 4. Unpublish the blob, revalidate the dynamic page, and wait to regenerate
40-
await page.goto(new URL('/cms/unpublish', dynamicCms.url).href)
41-
await page.goto(new URL('/api/revalidate?path=/content/blog', dynamicCms.url).href)
42-
await page.waitForTimeout(1000)
43-
44-
// 5. Verify the status and headers of the dynamic page
45-
const response3 = await page.goto(new URL('/content/blog', dynamicCms.url).href)
46-
const headers3 = response3?.headers() || {}
47-
48-
expect(response3?.status()).toEqual(404)
49-
expect(headers3['cache-control']).toEqual('public,max-age=0,must-revalidate')
50-
expect(headers3['cache-status']).toMatch(
51-
/"Next.js"; fwd=miss, "Netlify Durable"; fwd=stale; ttl=[0-9]+; stored, "Netlify Edge"; fwd=(stale|miss)/,
52-
)
53-
expect(headers3['netlify-cache-tag']).toEqual('_n_t_/content/blog')
54-
expect(headers3['netlify-cdn-cache-control']).toMatch(
55-
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/,
56-
)
20+
// repeat Publish and Unpublish to ensure the flow is repeatable
21+
for (let i = 0; i < 2; i++) {
22+
// 2. Publish the blob, revalidate the dynamic page, and wait to regenerate
23+
await page.goto(new URL('/cms/publish', dynamicCms.url).href)
24+
await page.goto(new URL('/api/revalidate?path=/content/blog', dynamicCms.url).href)
25+
await page.waitForTimeout(1000)
26+
27+
// 3. Verify the status and headers of the dynamic page
28+
const response2 = await page.goto(new URL('/content/blog', dynamicCms.url).href)
29+
const headers2 = response2?.headers() || {}
30+
31+
expect(response2?.status()).toEqual(200)
32+
expect(headers2['cache-control']).toEqual('public,max-age=0,must-revalidate')
33+
expect(headers2['cache-status']).toMatch(
34+
/"Next.js"; hit, "Netlify Durable"; fwd=stale; ttl=[0-9]+; stored, "Netlify Edge"; fwd=(stale|miss)/,
35+
)
36+
expect(headers2['netlify-cache-tag']).toEqual('_n_t_/content/blog')
37+
expect(headers2['netlify-cdn-cache-control']).toMatch(
38+
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/,
39+
)
40+
41+
// 4. Unpublish the blob, revalidate the dynamic page, and wait to regenerate
42+
await page.goto(new URL('/cms/unpublish', dynamicCms.url).href)
43+
await page.goto(new URL('/api/revalidate?path=/content/blog', dynamicCms.url).href)
44+
await page.waitForTimeout(1000)
45+
46+
// 5. Verify the status and headers of the dynamic page
47+
const response3 = await page.goto(new URL('/content/blog', dynamicCms.url).href)
48+
const headers3 = response3?.headers() || {}
49+
50+
expect(response3?.status()).toEqual(404)
51+
expect(headers3['cache-control']).toEqual('public,max-age=0,must-revalidate')
52+
expect(headers3['cache-status']).toMatch(
53+
/"Next.js"; fwd=miss, "Netlify Durable"; fwd=stale; ttl=[0-9]+; stored, "Netlify Edge"; fwd=(stale|miss)/,
54+
)
55+
expect(headers3['netlify-cache-tag']).toEqual('_n_t_/content/blog')
56+
expect(headers3['netlify-cdn-cache-control']).toMatch(
57+
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/,
58+
)
59+
}
5760
})
5861
})

0 commit comments

Comments
 (0)