@@ -35,6 +35,7 @@ test<FixtureTestContext>('should revalidate a route by tag', async (ctx) => {
35
35
// test the function call
36
36
const post1 = await invokeFunction ( ctx , { url : '/static-fetch-1' } )
37
37
const post1Date = load ( post1 . body ) ( '[data-testid="date-now"]' ) . text ( )
38
+ const post1Quote = load ( post1 . body ) ( '[data-testid="quote"]' ) . text ( )
38
39
expect ( post1 . statusCode ) . toBe ( 200 )
39
40
expect ( load ( post1 . body ) ( 'h1' ) . text ( ) ) . toBe ( 'Hello, Static Fetch 1' )
40
41
expect ( post1 . headers , 'a cache hit on the first invocation of a prerendered page' ) . toEqual (
@@ -53,6 +54,7 @@ test<FixtureTestContext>('should revalidate a route by tag', async (ctx) => {
53
54
54
55
const post2 = await invokeFunction ( ctx , { url : '/static-fetch-1' } )
55
56
const post2Date = load ( post2 . body ) ( '[data-testid="date-now"]' ) . text ( )
57
+ const post2Quote = load ( post2 . body ) ( '[data-testid="quote"]' ) . text ( )
56
58
expect ( post2 . statusCode ) . toBe ( 200 )
57
59
expect ( load ( post2 . body ) ( 'h1' ) . text ( ) ) . toBe ( 'Hello, Static Fetch 1' )
58
60
expect ( post2 . headers , 'a cache miss on the on demand revalidated page' ) . toEqual (
@@ -62,12 +64,14 @@ test<FixtureTestContext>('should revalidate a route by tag', async (ctx) => {
62
64
} ) ,
63
65
)
64
66
expect ( post2Date ) . not . toBe ( post1Date )
67
+ expect ( post2Quote ) . not . toBe ( post1Quote )
65
68
66
69
// it does not wait for the cache.set so we have to manually wait here until the blob storage got populated
67
70
await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 100 ) )
68
71
69
72
const post3 = await invokeFunction ( ctx , { url : '/static-fetch-1' } )
70
73
const post3Date = load ( post3 . body ) ( '[data-testid="date-now"]' ) . text ( )
74
+ const post3Quote = load ( post3 . body ) ( '[data-testid="quote"]' ) . text ( )
71
75
expect ( post3 . statusCode ) . toBe ( 200 )
72
76
expect ( load ( post3 . body ) ( 'h1' ) . text ( ) ) . toBe ( 'Hello, Static Fetch 1' )
73
77
expect ( post3 . headers , 'a cache hit on the revalidated and regenerated page' ) . toEqual (
@@ -77,4 +81,26 @@ test<FixtureTestContext>('should revalidate a route by tag', async (ctx) => {
77
81
} ) ,
78
82
)
79
83
expect ( post3Date ) . toBe ( post2Date )
84
+ expect ( post3Quote ) . toBe ( post2Quote )
85
+
86
+ const revalidate2 = await invokeFunction ( ctx , { url : '/api/on-demand-revalidate/tag' } )
87
+ expect ( revalidate2 . statusCode ) . toBe ( 200 )
88
+ expect ( JSON . parse ( revalidate2 . body ) ) . toEqual ( { revalidated : true , now : expect . any ( String ) } )
89
+
90
+ // it does not wait for the revalidation
91
+ await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 100 ) )
92
+
93
+ const post4 = await invokeFunction ( ctx , { url : '/static-fetch-1' } )
94
+ const post4Date = load ( post4 . body ) ( '[data-testid="date-now"]' ) . text ( )
95
+ const post4Quote = load ( post4 . body ) ( '[data-testid="quote"]' ) . text ( )
96
+ expect ( post4 . statusCode ) . toBe ( 200 )
97
+ expect ( load ( post4 . body ) ( 'h1' ) . text ( ) ) . toBe ( 'Hello, Static Fetch 1' )
98
+ expect ( post4 . headers , 'a cache miss on the on demand revalidated page' ) . toEqual (
99
+ expect . objectContaining ( {
100
+ 'cache-status' : '"Next.js"; fwd=miss' ,
101
+ 'netlify-cdn-cache-control' : 's-maxage=31536000, stale-while-revalidate=31536000' ,
102
+ } ) ,
103
+ )
104
+ expect ( post4Date ) . not . toBe ( post3Date )
105
+ expect ( post4Quote ) . not . toBe ( post3Quote )
80
106
} )
0 commit comments