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
+ / " N e x t .j s " ; h i t , " N e t l i f y D u r a b l e " ; f w d = s t a l e ; t t l = [ 0 - 9 ] + ; s t o r e d , " N e t l i f y E d g e " ; f w d = s t a l e /
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
+ / " N e x t .j s " ; f w d = m i s s , " N e t l i f y D u r a b l e " ; f w d = s t a l e ; t t l = [ 0 - 9 ] + ; s t o r e d , " N e t l i f y E d g e " ; f w d = s t a l e /
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
+ } )
0 commit comments