Skip to content

Commit 3e77d69

Browse files
authored
improve next-image-proxy test (vercel#56893)
This fixes a warning where the test server was exiting before all the proxy requests finished. This also throws an error to fail the test if any of the proxied requests aren't fulfilled. [slack x-ref](https://vercel.slack.com/archives/C04DUD7EB1B/p1697465502593889?thread_ts=1697143786.511779&cid=C04DUD7EB1B)
1 parent 54145b4 commit 3e77d69

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

test/e2e/app-dir/next-image/next-image-proxy.test.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { join } from 'path'
2-
import { findPort } from 'next-test-utils'
2+
import { findPort, check } from 'next-test-utils'
33
import https from 'https'
44
import httpProxy from 'http-proxy'
55
import fs from 'fs'
@@ -40,7 +40,7 @@ createNextDescribe(
4040
})
4141

4242
proxy.on('error', (err) => {
43-
console.warn('Failed to proxy', err)
43+
throw new Error('Failed to proxy: ' + err.message)
4444
})
4545

4646
await new Promise<void>((resolve) => {
@@ -50,6 +50,7 @@ createNextDescribe(
5050

5151
it('loads images without any errors', async () => {
5252
let failCount = 0
53+
let fulfilledCount = 0
5354

5455
const browser = await webdriver(`https://localhost:${proxyPort}`, '/', {
5556
ignoreHTTPSErrors: true,
@@ -66,6 +67,8 @@ createNextDescribe(
6667
console.log(`Request failed: ${url}`)
6768
failCount++
6869
}
70+
71+
fulfilledCount++
6972
})
7073
},
7174
})
@@ -77,10 +80,15 @@ createNextDescribe(
7780
'/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.3f1a293b.png&w=828&q=90'
7881
)
7982

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')
8189
})
8290

83-
afterAll(async () => {
91+
afterAll(() => {
8492
proxyServer.close()
8593
})
8694
}

0 commit comments

Comments
 (0)