@@ -174,12 +174,12 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
174
174
)
175
175
176
176
if ( fallbackWasServed ) {
177
- const loading = await page . textContent ( '[data-testid=" loading"]' )
177
+ const loading = await page . getByTestId ( ' loading' ) . textContent ( )
178
178
expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
179
179
}
180
180
181
- const date1 = await page . textContent ( '[data-testid=" date-now"]' )
182
- const h1 = await page . textContent ( 'h1' )
181
+ const date1 = await page . getByTestId ( ' date-now' ) . textContent ( )
182
+ const h1 = await page . locator ( 'h1' ) . textContent ( )
183
183
expect ( h1 ) . toBe ( expectedH1Content )
184
184
185
185
// check json route
@@ -238,7 +238,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
238
238
)
239
239
240
240
// the page is cached
241
- const date2 = await page . textContent ( '[data-testid=" date-now"]' )
241
+ const date2 = await page . getByTestId ( ' date-now' ) . textContent ( )
242
242
expect ( date2 ) . toBe ( date1 )
243
243
244
244
// check json route
@@ -299,7 +299,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
299
299
expect ( headers3 ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
300
300
301
301
// the page has now an updated date
302
- const date3 = await page . textContent ( '[data-testid=" date-now"]' )
302
+ const date3 = await page . getByTestId ( ' date-now' ) . textContent ( )
303
303
expect ( date3 ) . not . toBe ( date2 )
304
304
305
305
// check json route
@@ -366,7 +366,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
366
366
} ,
367
367
)
368
368
expect ( response1 ?. status ( ) ) . toBe ( 200 )
369
- const date1 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
369
+ const date1 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
370
370
371
371
// ensure response was produced before invocation (served from cache)
372
372
expect ( date1 . localeCompare ( beforeFetch ) ) . toBeLessThan ( 0 )
@@ -391,7 +391,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
391
391
} ,
392
392
)
393
393
expect ( response2 ?. status ( ) ) . toBe ( 200 )
394
- const date2 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
394
+ const date2 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
395
395
396
396
// ensure response was produced after initial invocation
397
397
expect ( beforeFetch . localeCompare ( date2 ) ) . toBeLessThan ( 0 )
@@ -416,7 +416,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
416
416
)
417
417
418
418
// ensure response was NOT produced before invocation
419
- const date1 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
419
+ const date1 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
420
420
expect ( date1 . localeCompare ( beforeFirstFetch ) ) . toBeGreaterThan ( 0 )
421
421
422
422
// allow page to get stale
@@ -431,7 +431,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
431
431
/ s - m a x a g e = 6 0 , s t a l e - w h i l e - r e v a l i d a t e = [ 0 - 9 ] + , d u r a b l e / ,
432
432
)
433
433
434
- const date2 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
434
+ const date2 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
435
435
expect ( date2 ) . toBe ( date1 )
436
436
437
437
// wait a bit to ensure background work has a chance to finish
@@ -450,7 +450,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
450
450
/ s - m a x a g e = 6 0 , s t a l e - w h i l e - r e v a l i d a t e = [ 0 - 9 ] + , d u r a b l e / ,
451
451
)
452
452
453
- const date3 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
453
+ const date3 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
454
454
expect ( date3 . localeCompare ( date2 ) ) . toBeGreaterThan ( 0 )
455
455
} )
456
456
@@ -469,7 +469,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
469
469
const headers = response ?. headers ( ) || { }
470
470
expect ( response ?. status ( ) ) . toBe ( 404 )
471
471
472
- expect ( await page . textContent ( 'p ') ) . toBe ( 'Custom 404 page' )
472
+ await expect ( page . getByTestId ( 'custom-404 ') ) . toHaveText ( 'Custom 404 page' )
473
473
474
474
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
475
475
// after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that
@@ -493,7 +493,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
493
493
const headers = response ?. headers ( ) || { }
494
494
expect ( response ?. status ( ) ) . toBe ( 404 )
495
495
496
- expect ( await page . textContent ( 'p ') ) . toBe ( 'Custom 404 page' )
496
+ await expect ( page . getByTestId ( 'custom-404 ') ) . toHaveText ( 'Custom 404 page' )
497
497
498
498
expect ( headers [ 'debug-netlify-cdn-cache-control' ] ) . toBe (
499
499
nextVersionSatisfies ( '>=15.0.0-canary.187' )
@@ -748,12 +748,12 @@ test.describe('Page Router with basePath and i18n', () => {
748
748
)
749
749
750
750
if ( fallbackWasServedImplicitLocale ) {
751
- const loading = await page . textContent ( '[data-testid=" loading"]' )
751
+ const loading = await page . getByTestId ( ' loading' ) . textContent ( )
752
752
expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
753
753
}
754
754
755
- const date1ImplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
756
- const h1ImplicitLocale = await page . textContent ( 'h1' )
755
+ const date1ImplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
756
+ const h1ImplicitLocale = await page . locator ( 'h1' ) . textContent ( )
757
757
expect ( h1ImplicitLocale ) . toBe ( expectedH1Content )
758
758
759
759
const response1ExplicitLocale = await pollUntilHeadersMatch (
@@ -790,12 +790,12 @@ test.describe('Page Router with basePath and i18n', () => {
790
790
)
791
791
792
792
if ( fallbackWasServedExplicitLocale ) {
793
- const loading = await page . textContent ( '[data-testid=" loading"]' )
793
+ const loading = await page . getByTestId ( ' loading' ) . textContent ( )
794
794
expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
795
795
}
796
796
797
- const date1ExplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
798
- const h1ExplicitLocale = await page . textContent ( 'h1' )
797
+ const date1ExplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
798
+ const h1ExplicitLocale = await page . locator ( 'h1' ) . textContent ( )
799
799
expect ( h1ExplicitLocale ) . toBe ( expectedH1Content )
800
800
801
801
// implicit and explicit locale paths should be the same (same cached response)
@@ -861,7 +861,7 @@ test.describe('Page Router with basePath and i18n', () => {
861
861
)
862
862
863
863
// the page is cached
864
- const date2ImplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
864
+ const date2ImplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
865
865
expect ( date2ImplicitLocale ) . toBe ( date1ImplicitLocale )
866
866
867
867
const response2ExplicitLocale = await pollUntilHeadersMatch (
@@ -893,7 +893,7 @@ test.describe('Page Router with basePath and i18n', () => {
893
893
)
894
894
895
895
// the page is cached
896
- const date2ExplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
896
+ const date2ExplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
897
897
expect ( date2ExplicitLocale ) . toBe ( date1ExplicitLocale )
898
898
899
899
// check json route
@@ -961,7 +961,7 @@ test.describe('Page Router with basePath and i18n', () => {
961
961
expect ( headers3ImplicitLocale ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
962
962
963
963
// the page has now an updated date
964
- const date3ImplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
964
+ const date3ImplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
965
965
expect ( date3ImplicitLocale ) . not . toBe ( date2ImplicitLocale )
966
966
967
967
const response3ExplicitLocale = await pollUntilHeadersMatch (
@@ -984,7 +984,7 @@ test.describe('Page Router with basePath and i18n', () => {
984
984
expect ( headers3ExplicitLocale ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
985
985
986
986
// the page has now an updated date
987
- const date3ExplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
987
+ const date3ExplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
988
988
expect ( date3ExplicitLocale ) . not . toBe ( date2ExplicitLocale )
989
989
990
990
// implicit and explicit locale paths should be the same (same cached response)
@@ -1057,7 +1057,7 @@ test.describe('Page Router with basePath and i18n', () => {
1057
1057
expect ( headers4ImplicitLocale ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
1058
1058
1059
1059
// the page has now an updated date
1060
- const date4ImplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
1060
+ const date4ImplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
1061
1061
expect ( date4ImplicitLocale ) . not . toBe ( date3ImplicitLocale )
1062
1062
1063
1063
const response4ExplicitLocale = await pollUntilHeadersMatch (
@@ -1080,7 +1080,7 @@ test.describe('Page Router with basePath and i18n', () => {
1080
1080
expect ( headers4ExplicitLocale ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
1081
1081
1082
1082
// the page has now an updated date
1083
- const date4ExplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
1083
+ const date4ExplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
1084
1084
expect ( date4ExplicitLocale ) . not . toBe ( date3ExplicitLocale )
1085
1085
1086
1086
// implicit and explicit locale paths should be the same (same cached response)
@@ -1173,12 +1173,12 @@ test.describe('Page Router with basePath and i18n', () => {
1173
1173
)
1174
1174
1175
1175
if ( fallbackWasServed ) {
1176
- const loading = await page . textContent ( '[data-testid=" loading"]' )
1176
+ const loading = await page . getByTestId ( ' loading' ) . textContent ( )
1177
1177
expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
1178
1178
}
1179
1179
1180
- const date1 = await page . textContent ( '[data-testid=" date-now"]' )
1181
- const h1 = await page . textContent ( 'h1' )
1180
+ const date1 = await page . getByTestId ( ' date-now' ) . textContent ( )
1181
+ const h1 = await page . locator ( 'h1' ) . textContent ( )
1182
1182
expect ( h1 ) . toBe ( expectedH1Content )
1183
1183
1184
1184
// check json route
@@ -1241,7 +1241,7 @@ test.describe('Page Router with basePath and i18n', () => {
1241
1241
)
1242
1242
1243
1243
// the page is cached
1244
- const date2 = await page . textContent ( '[data-testid=" date-now"]' )
1244
+ const date2 = await page . getByTestId ( ' date-now' ) . textContent ( )
1245
1245
expect ( date2 ) . toBe ( date1 )
1246
1246
1247
1247
// check json route
@@ -1309,7 +1309,7 @@ test.describe('Page Router with basePath and i18n', () => {
1309
1309
expect ( headers3 ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
1310
1310
1311
1311
// the page has now an updated date
1312
- const date3 = await page . textContent ( '[data-testid=" date-now"]' )
1312
+ const date3 = await page . getByTestId ( ' date-now' ) . textContent ( )
1313
1313
expect ( date3 ) . not . toBe ( date2 )
1314
1314
1315
1315
// check json route
@@ -1360,7 +1360,7 @@ test.describe('Page Router with basePath and i18n', () => {
1360
1360
const headers = response ?. headers ( ) || { }
1361
1361
expect ( response ?. status ( ) ) . toBe ( 404 )
1362
1362
1363
- expect ( await page . textContent ( 'p ') ) . toBe ( 'Custom 404 page for locale: en' )
1363
+ await expect ( page . getByTestId ( 'custom-404 ') ) . toHaveText ( 'Custom 404 page for locale: en' )
1364
1364
1365
1365
expect ( headers [ 'debug-netlify-cdn-cache-control' ] ) . toMatch (
1366
1366
/ n o - c a c h e , n o - s t o r e , m a x - a g e = 0 , m u s t - r e v a l i d a t e , d u r a b l e / m,
@@ -1378,7 +1378,7 @@ test.describe('Page Router with basePath and i18n', () => {
1378
1378
const headers = response ?. headers ( ) || { }
1379
1379
expect ( response ?. status ( ) ) . toBe ( 404 )
1380
1380
1381
- expect ( await page . textContent ( 'p ') ) . toBe ( 'Custom 404 page for locale: en' )
1381
+ await expect ( page . getByTestId ( 'custom-404 ') ) . toHaveText ( 'Custom 404 page for locale: en' )
1382
1382
1383
1383
// Prior to v14.2.4 notFound pages are not cacheable
1384
1384
// https://github.com/vercel/next.js/pull/66674
0 commit comments