@@ -16,7 +16,6 @@ import {
16
16
nextStart ,
17
17
renderViaHTTP ,
18
18
retry ,
19
- waitFor ,
20
19
} from 'next-test-utils'
21
20
import webdriver from 'next-webdriver'
22
21
import { join } from 'path'
@@ -612,16 +611,17 @@ function runTests(mode: 'dev' | 'server') {
612
611
`/_next/image?url=%2Ftest.png&w=640&q=75 1x, /_next/image?url=%2Ftest.png&w=828&q=75 2x`
613
612
)
614
613
if ( mode === 'dev' ) {
615
- await waitFor ( 1000 )
616
- const warnings = ( await browser . log ( ) )
617
- . map ( ( log ) => log . message )
618
- . join ( '\n' )
619
- expect ( warnings ) . toMatch (
620
- / I m a g e w i t h s r c " \/ w i d e .p n g " h a s e i t h e r w i d t h o r h e i g h t m o d i f i e d , b u t n o t t h e o t h e r ./ gm
621
- )
622
- expect ( warnings ) . not . toMatch (
623
- / I m a g e w i t h s r c " \/ t e s t .p n g " h a s e i t h e r w i d t h o r h e i g h t m o d i f i e d , b u t n o t t h e o t h e r ./ gm
624
- )
614
+ await retry ( async ( ) => {
615
+ const warnings = ( await browser . log ( ) )
616
+ . map ( ( log ) => log . message )
617
+ . join ( '\n' )
618
+ expect ( warnings ) . toMatch (
619
+ / I m a g e w i t h s r c " \/ w i d e .p n g " h a s e i t h e r w i d t h o r h e i g h t m o d i f i e d , b u t n o t t h e o t h e r ./ gm
620
+ )
621
+ expect ( warnings ) . not . toMatch (
622
+ / I m a g e w i t h s r c " \/ t e s t .p n g " h a s e i t h e r w i d t h o r h e i g h t m o d i f i e d , b u t n o t t h e o t h e r ./ gm
623
+ )
624
+ } )
625
625
}
626
626
} )
627
627
@@ -923,7 +923,6 @@ function runTests(mode: 'dev' | 'server') {
923
923
924
924
it ( 'should show error when invalid height prop' , async ( ) => {
925
925
const browser = await webdriver ( appPort , '/invalid-height' )
926
-
927
926
await assertHasRedbox ( browser )
928
927
expect ( await getRedboxHeader ( browser ) ) . toContain (
929
928
`Image with src "/test.jpg" has invalid "height" property. Expected a numeric value in pixels but received "50vh".`
@@ -1025,14 +1024,15 @@ function runTests(mode: 'dev' | 'server') {
1025
1024
}
1026
1025
return 'done'
1027
1026
} , 'done' )
1028
- await waitFor ( 1000 )
1029
- const warnings = ( await browser . log ( ) )
1030
- . map ( ( log ) => log . message )
1031
- . join ( '\n' )
1032
- await assertNoRedbox ( browser )
1033
- expect ( warnings ) . toMatch (
1034
- / I m a g e w i t h s r c ( .* ) t e s t ( .* ) w a s d e t e c t e d a s t h e L a r g e s t C o n t e n t f u l P a i n t / gm
1035
- )
1027
+ await retry ( async ( ) => {
1028
+ const warnings = ( await browser . log ( ) )
1029
+ . map ( ( log ) => log . message )
1030
+ . join ( '\n' )
1031
+ await assertNoRedbox ( browser )
1032
+ expect ( warnings ) . toMatch (
1033
+ / I m a g e w i t h s r c ( .* ) t e s t ( .* ) w a s d e t e c t e d a s t h e L a r g e s t C o n t e n t f u l P a i n t / gm
1034
+ )
1035
+ } )
1036
1036
} )
1037
1037
1038
1038
it ( 'should warn when loader is missing width' , async ( ) => {
@@ -1112,14 +1112,15 @@ function runTests(mode: 'dev' | 'server') {
1112
1112
}
1113
1113
return 'done'
1114
1114
} , 'done' )
1115
- await waitFor ( 1000 )
1116
- const warnings = ( await browser . log ( ) )
1117
- . map ( ( log ) => log . message )
1118
- . filter ( ( log ) => log . startsWith ( 'Image with src' ) )
1119
- expect ( warnings [ 0 ] ) . toMatch (
1120
- 'Image with src "/test.png" was detected as the Largest Contentful Paint (LCP).'
1121
- )
1122
- expect ( warnings . length ) . toBe ( 1 )
1115
+ await retry ( async ( ) => {
1116
+ const warnings = ( await browser . log ( ) )
1117
+ . map ( ( log ) => log . message )
1118
+ . filter ( ( log ) => log . startsWith ( 'Image with src' ) )
1119
+ expect ( warnings [ 0 ] ) . toMatch (
1120
+ 'Image with src "/test.png" was detected as the Largest Contentful Paint (LCP).'
1121
+ )
1122
+ expect ( warnings . length ) . toBe ( 1 )
1123
+ } )
1123
1124
} )
1124
1125
} else {
1125
1126
//server-only tests
@@ -1178,11 +1179,11 @@ function runTests(mode: 'dev' | 'server') {
1178
1179
return 'result-correct'
1179
1180
} , / r e s u l t - c o r r e c t / )
1180
1181
1181
- await waitFor ( 1000 )
1182
-
1183
- const computedWidth = await getComputed ( browser , id , 'width ' )
1184
- const computedHeight = await getComputed ( browser , id , 'height' )
1185
- expect ( getRatio ( computedWidth , computedHeight ) ) . toBeCloseTo ( 1 , 1 )
1182
+ await retry ( async ( ) => {
1183
+ const computedWidth = await getComputed ( browser , id , 'width' )
1184
+ const computedHeight = await getComputed ( browser , id , 'height ' )
1185
+ expect ( getRatio ( computedWidth , computedHeight ) ) . toBeCloseTo ( 1 , 1 )
1186
+ } )
1186
1187
} )
1187
1188
1188
1189
it ( 'should apply style inheritance for img elements but not wrapper elements' , async ( ) => {
@@ -1222,33 +1223,34 @@ function runTests(mode: 'dev' | 'server') {
1222
1223
const browser = await webdriver ( appPort , '/style-filter' )
1223
1224
await check ( ( ) => getSrc ( browser , 'img-plain' ) , / ^ \/ _ n e x t \/ i m a g e / )
1224
1225
await check ( ( ) => getSrc ( browser , 'img-blur' ) , / ^ \/ _ n e x t \/ i m a g e / )
1225
- await waitFor ( 1000 )
1226
1226
1227
- expect ( await getComputedStyle ( browser , 'img-plain' , 'filter' ) ) . toBe (
1228
- 'opacity(0.5)'
1229
- )
1230
- expect (
1231
- await getComputedStyle ( browser , 'img-plain' , 'background-size' )
1232
- ) . toBe ( '30%' )
1233
- expect (
1234
- await getComputedStyle ( browser , 'img-plain' , 'background-image' )
1235
- ) . toMatch ( 'iVBORw0KGgo=' )
1236
- expect (
1237
- await getComputedStyle ( browser , 'img-plain' , 'background-position' )
1238
- ) . toBe ( '1px 2px' )
1227
+ await retry ( async ( ) => {
1228
+ expect ( await getComputedStyle ( browser , 'img-plain' , 'filter' ) ) . toBe (
1229
+ 'opacity(0.5)'
1230
+ )
1231
+ expect (
1232
+ await getComputedStyle ( browser , 'img-plain' , 'background-size' )
1233
+ ) . toBe ( '30%' )
1234
+ expect (
1235
+ await getComputedStyle ( browser , 'img-plain' , 'background-image' )
1236
+ ) . toMatch ( 'iVBORw0KGgo=' )
1237
+ expect (
1238
+ await getComputedStyle ( browser , 'img-plain' , 'background-position' )
1239
+ ) . toBe ( '1px 2px' )
1239
1240
1240
- expect ( await getComputedStyle ( browser , 'img-blur' , 'filter' ) ) . toBe (
1241
- 'opacity(0.5)'
1242
- )
1243
- expect ( await getComputedStyle ( browser , 'img-blur' , 'background-size' ) ) . toBe (
1244
- '30%'
1245
- )
1246
- expect (
1247
- await getComputedStyle ( browser , 'img-blur' , 'background-image' )
1248
- ) . toMatch ( 'iVBORw0KGgo=' )
1249
- expect (
1250
- await getComputedStyle ( browser , 'img-blur' , 'background-position' )
1251
- ) . toBe ( '1px 2px' )
1241
+ expect ( await getComputedStyle ( browser , 'img-blur' , 'filter' ) ) . toBe (
1242
+ 'opacity(0.5)'
1243
+ )
1244
+ expect (
1245
+ await getComputedStyle ( browser , 'img-blur' , 'background-size' )
1246
+ ) . toBe ( '30%' )
1247
+ expect (
1248
+ await getComputedStyle ( browser , 'img-blur' , 'background-image' )
1249
+ ) . toMatch ( 'iVBORw0KGgo=' )
1250
+ expect (
1251
+ await getComputedStyle ( browser , 'img-blur' , 'background-position' )
1252
+ ) . toBe ( '1px 2px' )
1253
+ } )
1252
1254
} )
1253
1255
1254
1256
it ( 'should emit image for next/dynamic with non ssr case' , async ( ) => {
@@ -1298,43 +1300,46 @@ function runTests(mode: 'dev' | 'server') {
1298
1300
if ( mode === 'dev' ) {
1299
1301
it ( 'should not log incorrect warnings' , async ( ) => {
1300
1302
const browser = await webdriver ( appPort , '/fill' )
1301
- await waitFor ( 1000 )
1302
- const warnings = ( await browser . log ( ) )
1303
- . map ( ( log ) => log . message )
1304
- . join ( '\n' )
1305
- expect ( warnings ) . not . toMatch ( / I m a g e w i t h s r c ( .* ) h a s " f i l l " / gm)
1306
- expect ( warnings ) . not . toMatch (
1307
- / I m a g e w i t h s r c ( .* ) i s s m a l l e r t h a n 4 0 x 4 0 . C o n s i d e r r e m o v i n g ( .* ) / gm
1308
- )
1303
+ await retry ( async ( ) => {
1304
+ const warnings = ( await browser . log ( ) )
1305
+ . map ( ( log ) => log . message )
1306
+ . join ( '\n' )
1307
+ expect ( warnings ) . not . toMatch ( / I m a g e w i t h s r c ( .* ) h a s " f i l l " / gm)
1308
+ expect ( warnings ) . not . toMatch (
1309
+ / I m a g e w i t h s r c ( .* ) i s s m a l l e r t h a n 4 0 x 4 0 . C o n s i d e r r e m o v i n g ( .* ) / gm
1310
+ )
1311
+ } )
1309
1312
} )
1310
1313
it ( 'should log warnings when using fill mode incorrectly' , async ( ) => {
1311
1314
const browser = await webdriver ( appPort , '/fill-warnings' )
1312
- await waitFor ( 1000 )
1313
- const warnings = ( await browser . log ( ) )
1314
- . map ( ( log ) => log . message )
1315
- . join ( '\n' )
1316
- expect ( warnings ) . toContain (
1317
- 'Image with src "/wide.png" has "fill" and parent element with invalid "position". Provided "static" should be one of absolute,fixed,relative.'
1318
- )
1319
- expect ( warnings ) . toContain (
1320
- 'Image with src "/wide.png" has "fill" and a height value of 0. This is likely because the parent element of the image has not been styled to have a set height.'
1321
- )
1322
- expect ( warnings ) . toContain (
1323
- 'Image with src "/wide.png" has "fill" but is missing "sizes" prop. Please add it to improve page performance. Read more:'
1324
- )
1325
- expect ( warnings ) . toContain (
1326
- 'Image with src "/test.png" has "fill" prop and "sizes" prop of "100vw", but image is not rendered at full viewport width. Please adjust "sizes" to improve page performance. Read more:'
1327
- )
1315
+ await retry ( async ( ) => {
1316
+ const warnings = ( await browser . log ( ) )
1317
+ . map ( ( log ) => log . message )
1318
+ . join ( '\n' )
1319
+ expect ( warnings ) . toContain (
1320
+ 'Image with src "/wide.png" has "fill" and parent element with invalid "position". Provided "static" should be one of absolute,fixed,relative.'
1321
+ )
1322
+ expect ( warnings ) . toContain (
1323
+ 'Image with src "/wide.png" has "fill" and a height value of 0. This is likely because the parent element of the image has not been styled to have a set height.'
1324
+ )
1325
+ expect ( warnings ) . toContain (
1326
+ 'Image with src "/wide.png" has "fill" but is missing "sizes" prop. Please add it to improve page performance. Read more:'
1327
+ )
1328
+ expect ( warnings ) . toContain (
1329
+ 'Image with src "/test.png" has "fill" prop and "sizes" prop of "100vw", but image is not rendered at full viewport width. Please adjust "sizes" to improve page performance. Read more:'
1330
+ )
1331
+ } )
1328
1332
} )
1329
1333
it ( 'should not log warnings when image unmounts' , async ( ) => {
1330
1334
const browser = await webdriver ( appPort , '/should-not-warn-unmount' )
1331
- await waitFor ( 1000 )
1332
- const warnings = ( await browser . log ( ) )
1333
- . map ( ( log ) => log . message )
1334
- . join ( '\n' )
1335
- expect ( warnings ) . not . toContain (
1336
- 'Image with src "/test.jpg" has "fill" and parent element'
1337
- )
1335
+ await retry ( async ( ) => {
1336
+ const warnings = ( await browser . log ( ) )
1337
+ . map ( ( log ) => log . message )
1338
+ . join ( '\n' )
1339
+ expect ( warnings ) . not . toContain (
1340
+ 'Image with src "/test.jpg" has "fill" and parent element'
1341
+ )
1342
+ } )
1338
1343
} )
1339
1344
}
1340
1345
} )
@@ -1358,11 +1363,11 @@ function runTests(mode: 'dev' | 'server') {
1358
1363
return 'result-correct'
1359
1364
} , / r e s u l t - c o r r e c t / )
1360
1365
1361
- await waitFor ( 500 )
1362
-
1363
- const computedWidth = await getComputed ( browser , id , 'width ' )
1364
- const computedHeight = await getComputed ( browser , id , 'height' )
1365
- expect ( getRatio ( computedHeight , computedWidth ) ) . toBeCloseTo ( 0.75 , 1 )
1366
+ await retry ( async ( ) => {
1367
+ const computedWidth = await getComputed ( browser , id , 'width' )
1368
+ const computedHeight = await getComputed ( browser , id , 'height ' )
1369
+ expect ( getRatio ( computedHeight , computedWidth ) ) . toBeCloseTo ( 0.75 , 1 )
1370
+ } )
1366
1371
} )
1367
1372
}
1368
1373
@@ -1500,8 +1505,9 @@ function runTests(mode: 'dev' | 'server') {
1500
1505
1501
1506
it ( 'should be valid HTML' , async ( ) => {
1502
1507
const browser = await webdriver ( appPort , '/valid-html-w3c' )
1503
- await waitFor ( 1000 )
1504
- expect ( await browser . hasElementByCssSelector ( 'img' ) ) . toBeTruthy ( )
1508
+ await retry ( async ( ) =>
1509
+ expect ( await browser . hasElementByCssSelector ( 'img' ) ) . toBeTruthy ( )
1510
+ )
1505
1511
const url = await browser . url ( )
1506
1512
const result = ( await validateHTML ( {
1507
1513
url,
0 commit comments