@@ -51,51 +51,79 @@ export async function check(
51
51
52
52
test . describe ( 'Simple Page Router (no basePath, no i18n)' , ( ) => {
53
53
test . describe ( 'On-demand revalidate works correctly' , ( ) => {
54
- for ( const { label, prerendered, pagePath, revalidateApiBasePath, expectedH1Content } of [
54
+ for ( const {
55
+ label,
56
+ useFallback,
57
+ prerendered,
58
+ pagePath,
59
+ revalidateApiBasePath,
60
+ expectedH1Content,
61
+ } of [
55
62
{
56
- label : 'prerendered page with static path and awaited res.revalidate()' ,
63
+ label :
64
+ 'prerendered page with static path with fallback: blocking and awaited res.revalidate()' ,
57
65
prerendered : true ,
58
66
pagePath : '/static/revalidate-manual' ,
59
67
revalidateApiBasePath : '/api/revalidate' ,
60
68
expectedH1Content : 'Show #71' ,
61
69
} ,
62
70
{
63
- label : 'prerendered page with dynamic path and awaited res.revalidate()' ,
71
+ label :
72
+ 'prerendered page with dynamic path with fallback: blocking and awaited res.revalidate()' ,
64
73
prerendered : true ,
65
74
pagePath : '/products/prerendered' ,
66
75
revalidateApiBasePath : '/api/revalidate' ,
67
76
expectedH1Content : 'Product prerendered' ,
68
77
} ,
69
78
{
70
- label : 'not prerendered page with dynamic path and awaited res.revalidate()' ,
79
+ label :
80
+ 'not prerendered page with dynamic path with fallback: blocking and awaited res.revalidate()' ,
71
81
prerendered : false ,
72
82
pagePath : '/products/not-prerendered' ,
73
83
revalidateApiBasePath : '/api/revalidate' ,
74
84
expectedH1Content : 'Product not-prerendered' ,
75
85
} ,
76
86
{
77
- label : 'not prerendered page with dynamic path and not awaited res.revalidate()' ,
87
+ label :
88
+ 'not prerendered page with dynamic path with fallback: blocking and not awaited res.revalidate()' ,
78
89
prerendered : false ,
79
90
pagePath : '/products/not-prerendered-and-not-awaited-revalidation' ,
80
91
revalidateApiBasePath : '/api/revalidate-no-await' ,
81
92
expectedH1Content : 'Product not-prerendered-and-not-awaited-revalidation' ,
82
93
} ,
83
94
{
84
95
label :
85
- 'prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant' ,
96
+ 'prerendered page with dynamic path with fallback: blocking and awaited res.revalidate() - non-ASCII variant' ,
86
97
prerendered : true ,
87
98
pagePath : '/products/事前レンダリング,test' ,
88
99
revalidateApiBasePath : '/api/revalidate' ,
89
100
expectedH1Content : 'Product 事前レンダリング,test' ,
90
101
} ,
91
102
{
92
103
label :
93
- 'not prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant' ,
104
+ 'not prerendered page with dynamic path with fallback: blocking and awaited res.revalidate() - non-ASCII variant' ,
94
105
prerendered : false ,
95
106
pagePath : '/products/事前レンダリングされていない,test' ,
96
107
revalidateApiBasePath : '/api/revalidate' ,
97
108
expectedH1Content : 'Product 事前レンダリングされていない,test' ,
98
109
} ,
110
+ {
111
+ label :
112
+ 'prerendered page with dynamic path with fallback: true and awaited res.revalidate()' ,
113
+ prerendered : true ,
114
+ pagePath : '/fallback-true/prerendered' ,
115
+ revalidateApiBasePath : '/api/revalidate' ,
116
+ expectedH1Content : 'Product prerendered' ,
117
+ } ,
118
+ {
119
+ label :
120
+ 'not prerendered page with dynamic path with fallback: true and awaited res.revalidate()' ,
121
+ prerendered : false ,
122
+ useFallback : true ,
123
+ pagePath : '/fallback-true/not-prerendered' ,
124
+ revalidateApiBasePath : '/api/revalidate' ,
125
+ expectedH1Content : 'Product not-prerendered' ,
126
+ } ,
99
127
] ) {
100
128
test ( label , async ( { page, pollUntilHeadersMatch, pageRouter } ) => {
101
129
// in case there is retry or some other test did hit that path before
@@ -126,11 +154,23 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
126
154
const headers1 = response1 ?. headers ( ) || { }
127
155
expect ( response1 ?. status ( ) ) . toBe ( 200 )
128
156
expect ( headers1 [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
129
- expect ( headers1 [ 'netlify-cache-tag' ] ) . toBe ( `_n_t_${ encodeURI ( pagePath ) . toLowerCase ( ) } ` )
157
+
158
+ const fallbackWasServed =
159
+ useFallback && headers1 [ 'cache-status' ] . includes ( '"Next.js"; fwd=miss' )
160
+ expect ( headers1 [ 'netlify-cache-tag' ] ) . toBe (
161
+ fallbackWasServed ? undefined : `_n_t_${ encodeURI ( pagePath ) . toLowerCase ( ) } ` ,
162
+ )
130
163
expect ( headers1 [ 'netlify-cdn-cache-control' ] ) . toBe (
131
- 's-maxage=31536000, stale-while-revalidate=31536000, durable' ,
164
+ fallbackWasServed
165
+ ? undefined
166
+ : 's-maxage=31536000, stale-while-revalidate=31536000, durable' ,
132
167
)
133
168
169
+ if ( fallbackWasServed ) {
170
+ const loading = await page . textContent ( '[data-testid="loading"]' )
171
+ expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
172
+ }
173
+
134
174
const date1 = await page . textContent ( '[data-testid="date-now"]' )
135
175
const h1 = await page . textContent ( 'h1' )
136
176
expect ( h1 ) . toBe ( expectedH1Content )
@@ -446,7 +486,14 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
446
486
447
487
test . describe ( 'Page Router with basePath and i18n' , ( ) => {
448
488
test . describe ( 'Static revalidate works correctly' , ( ) => {
449
- for ( const { label, prerendered, pagePath, revalidateApiBasePath, expectedH1Content } of [
489
+ for ( const {
490
+ label,
491
+ useFallback,
492
+ prerendered,
493
+ pagePath,
494
+ revalidateApiBasePath,
495
+ expectedH1Content,
496
+ } of [
450
497
{
451
498
label : 'prerendered page with static path and awaited res.revalidate()' ,
452
499
prerendered : true ,
@@ -455,42 +502,62 @@ test.describe('Page Router with basePath and i18n', () => {
455
502
expectedH1Content : 'Show #71' ,
456
503
} ,
457
504
{
458
- label : 'prerendered page with dynamic path and awaited res.revalidate()' ,
505
+ label :
506
+ 'prerendered page with dynamic path with fallback: blocking and awaited res.revalidate()' ,
459
507
prerendered : true ,
460
508
pagePath : '/products/prerendered' ,
461
509
revalidateApiBasePath : '/api/revalidate' ,
462
510
expectedH1Content : 'Product prerendered' ,
463
511
} ,
464
512
{
465
- label : 'not prerendered page with dynamic path and awaited res.revalidate()' ,
513
+ label :
514
+ 'not prerendered page with dynamic path with fallback: blocking and awaited res.revalidate()' ,
466
515
prerendered : false ,
467
516
pagePath : '/products/not-prerendered' ,
468
517
revalidateApiBasePath : '/api/revalidate' ,
469
518
expectedH1Content : 'Product not-prerendered' ,
470
519
} ,
471
520
{
472
- label : 'not prerendered page with dynamic path and not awaited res.revalidate()' ,
521
+ label :
522
+ 'not prerendered page with dynamic path with fallback: blocking and not awaited res.revalidate()' ,
473
523
prerendered : false ,
474
524
pagePath : '/products/not-prerendered-and-not-awaited-revalidation' ,
475
525
revalidateApiBasePath : '/api/revalidate-no-await' ,
476
526
expectedH1Content : 'Product not-prerendered-and-not-awaited-revalidation' ,
477
527
} ,
478
528
{
479
529
label :
480
- 'prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant' ,
530
+ 'prerendered page with dynamic path with fallback: blocking and awaited res.revalidate() - non-ASCII variant' ,
481
531
prerendered : true ,
482
532
pagePath : '/products/事前レンダリング,test' ,
483
533
revalidateApiBasePath : '/api/revalidate' ,
484
534
expectedH1Content : 'Product 事前レンダリング,test' ,
485
535
} ,
486
536
{
487
537
label :
488
- 'not prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant' ,
538
+ 'not prerendered page with dynamic path with fallback: blocking and awaited res.revalidate() - non-ASCII variant' ,
489
539
prerendered : false ,
490
540
pagePath : '/products/事前レンダリングされていない,test' ,
491
541
revalidateApiBasePath : '/api/revalidate' ,
492
542
expectedH1Content : 'Product 事前レンダリングされていない,test' ,
493
543
} ,
544
+ {
545
+ label :
546
+ 'prerendered page with dynamic path with fallback: true and awaited res.revalidate()' ,
547
+ prerendered : true ,
548
+ pagePath : '/fallback-true/prerendered' ,
549
+ revalidateApiBasePath : '/api/revalidate' ,
550
+ expectedH1Content : 'Product prerendered' ,
551
+ } ,
552
+ {
553
+ label :
554
+ 'not prerendered page with dynamic path with fallback: true and awaited res.revalidate()' ,
555
+ prerendered : false ,
556
+ useFallback : true ,
557
+ pagePath : '/fallback-true/not-prerendered' ,
558
+ revalidateApiBasePath : '/api/revalidate' ,
559
+ expectedH1Content : 'Product not-prerendered' ,
560
+ } ,
494
561
] ) {
495
562
test . describe ( label , ( ) => {
496
563
test ( `default locale` , async ( { page, pollUntilHeadersMatch, pageRouterBasePathI18n } ) => {
@@ -528,13 +595,26 @@ test.describe('Page Router with basePath and i18n', () => {
528
595
const headers1ImplicitLocale = response1ImplicitLocale ?. headers ( ) || { }
529
596
expect ( response1ImplicitLocale ?. status ( ) ) . toBe ( 200 )
530
597
expect ( headers1ImplicitLocale [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
598
+
599
+ const fallbackWasServedImplicitLocale =
600
+ useFallback && headers1ImplicitLocale [ 'cache-status' ] . includes ( '"Next.js"; fwd=miss' )
601
+
531
602
expect ( headers1ImplicitLocale [ 'netlify-cache-tag' ] ) . toBe (
532
- `_n_t_/en${ encodeURI ( pagePath ) . toLowerCase ( ) } ` ,
603
+ fallbackWasServedImplicitLocale
604
+ ? undefined
605
+ : `_n_t_/en${ encodeURI ( pagePath ) . toLowerCase ( ) } ` ,
533
606
)
534
607
expect ( headers1ImplicitLocale [ 'netlify-cdn-cache-control' ] ) . toBe (
535
- 's-maxage=31536000, stale-while-revalidate=31536000, durable' ,
608
+ fallbackWasServedImplicitLocale
609
+ ? undefined
610
+ : 's-maxage=31536000, stale-while-revalidate=31536000, durable' ,
536
611
)
537
612
613
+ if ( fallbackWasServedImplicitLocale ) {
614
+ const loading = await page . textContent ( '[data-testid="loading"]' )
615
+ expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
616
+ }
617
+
538
618
const date1ImplicitLocale = await page . textContent ( '[data-testid="date-now"]' )
539
619
const h1ImplicitLocale = await page . textContent ( 'h1' )
540
620
expect ( h1ImplicitLocale ) . toBe ( expectedH1Content )
@@ -556,13 +636,25 @@ test.describe('Page Router with basePath and i18n', () => {
556
636
const headers1ExplicitLocale = response1ExplicitLocale ?. headers ( ) || { }
557
637
expect ( response1ExplicitLocale ?. status ( ) ) . toBe ( 200 )
558
638
expect ( headers1ExplicitLocale [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
639
+
640
+ const fallbackWasServedExplicitLocale =
641
+ useFallback && headers1ExplicitLocale [ 'cache-status' ] . includes ( '"Next.js"; fwd=miss' )
559
642
expect ( headers1ExplicitLocale [ 'netlify-cache-tag' ] ) . toBe (
560
- `_n_t_/en${ encodeURI ( pagePath ) . toLowerCase ( ) } ` ,
643
+ fallbackWasServedExplicitLocale
644
+ ? undefined
645
+ : `_n_t_/en${ encodeURI ( pagePath ) . toLowerCase ( ) } ` ,
561
646
)
562
647
expect ( headers1ExplicitLocale [ 'netlify-cdn-cache-control' ] ) . toBe (
563
- 's-maxage=31536000, stale-while-revalidate=31536000, durable' ,
648
+ fallbackWasServedExplicitLocale
649
+ ? undefined
650
+ : 's-maxage=31536000, stale-while-revalidate=31536000, durable' ,
564
651
)
565
652
653
+ if ( fallbackWasServedExplicitLocale ) {
654
+ const loading = await page . textContent ( '[data-testid="loading"]' )
655
+ expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
656
+ }
657
+
566
658
const date1ExplicitLocale = await page . textContent ( '[data-testid="date-now"]' )
567
659
const h1ExplicitLocale = await page . textContent ( 'h1' )
568
660
expect ( h1ExplicitLocale ) . toBe ( expectedH1Content )
@@ -910,11 +1002,23 @@ test.describe('Page Router with basePath and i18n', () => {
910
1002
const headers1 = response1 ?. headers ( ) || { }
911
1003
expect ( response1 ?. status ( ) ) . toBe ( 200 )
912
1004
expect ( headers1 [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
913
- expect ( headers1 [ 'netlify-cache-tag' ] ) . toBe ( `_n_t_/de${ encodeURI ( pagePath ) . toLowerCase ( ) } ` )
1005
+
1006
+ const fallbackWasServed =
1007
+ useFallback && headers1 [ 'cache-status' ] . includes ( '"Next.js"; fwd=miss' )
1008
+ expect ( headers1 [ 'netlify-cache-tag' ] ) . toBe (
1009
+ fallbackWasServed ? undefined : `_n_t_/de${ encodeURI ( pagePath ) . toLowerCase ( ) } ` ,
1010
+ )
914
1011
expect ( headers1 [ 'netlify-cdn-cache-control' ] ) . toBe (
915
- 's-maxage=31536000, stale-while-revalidate=31536000, durable' ,
1012
+ fallbackWasServed
1013
+ ? undefined
1014
+ : 's-maxage=31536000, stale-while-revalidate=31536000, durable' ,
916
1015
)
917
1016
1017
+ if ( fallbackWasServed ) {
1018
+ const loading = await page . textContent ( '[data-testid="loading"]' )
1019
+ expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
1020
+ }
1021
+
918
1022
const date1 = await page . textContent ( '[data-testid="date-now"]' )
919
1023
const h1 = await page . textContent ( 'h1' )
920
1024
expect ( h1 ) . toBe ( expectedH1Content )
0 commit comments