1
1
import { join } from 'path'
2
- import { findPort } from 'next-test-utils'
2
+ import { findPort , check } from 'next-test-utils'
3
3
import https from 'https'
4
4
import httpProxy from 'http-proxy'
5
5
import fs from 'fs'
@@ -40,7 +40,7 @@ createNextDescribe(
40
40
} )
41
41
42
42
proxy . on ( 'error' , ( err ) => {
43
- console . warn ( 'Failed to proxy' , err )
43
+ throw new Error ( 'Failed to proxy: ' + err . message )
44
44
} )
45
45
46
46
await new Promise < void > ( ( resolve ) => {
@@ -50,6 +50,7 @@ createNextDescribe(
50
50
51
51
it ( 'loads images without any errors' , async ( ) => {
52
52
let failCount = 0
53
+ let fulfilledCount = 0
53
54
54
55
const browser = await webdriver ( `https://localhost:${ proxyPort } ` , '/' , {
55
56
ignoreHTTPSErrors : true ,
@@ -66,6 +67,8 @@ createNextDescribe(
66
67
console . log ( `Request failed: ${ url } ` )
67
68
failCount ++
68
69
}
70
+
71
+ fulfilledCount ++
69
72
} )
70
73
} ,
71
74
} )
@@ -77,10 +80,15 @@ createNextDescribe(
77
80
'/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.3f1a293b.png&w=828&q=90'
78
81
)
79
82
80
- expect ( failCount ) . toBe ( 0 )
83
+ await check ( ( ) => {
84
+ // we expect 3 images to load and for none of them to have errors
85
+ if ( fulfilledCount === 3 && failCount === 0 ) {
86
+ return 'success'
87
+ }
88
+ } , 'success' )
81
89
} )
82
90
83
- afterAll ( async ( ) => {
91
+ afterAll ( ( ) => {
84
92
proxyServer . close ( )
85
93
} )
86
94
}
0 commit comments