Skip to content

Commit

Permalink
improve next-image-proxy test (#56893)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ztanner authored Oct 16, 2023
1 parent 54145b4 commit 3e77d69
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/e2e/app-dir/next-image/next-image-proxy.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'path'
import { findPort } from 'next-test-utils'
import { findPort, check } from 'next-test-utils'
import https from 'https'
import httpProxy from 'http-proxy'
import fs from 'fs'
Expand Down Expand Up @@ -40,7 +40,7 @@ createNextDescribe(
})

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

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

it('loads images without any errors', async () => {
let failCount = 0
let fulfilledCount = 0

const browser = await webdriver(`https://localhost:${proxyPort}`, '/', {
ignoreHTTPSErrors: true,
Expand All @@ -66,6 +67,8 @@ createNextDescribe(
console.log(`Request failed: ${url}`)
failCount++
}

fulfilledCount++
})
},
})
Expand All @@ -77,10 +80,15 @@ createNextDescribe(
'/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.3f1a293b.png&w=828&q=90'
)

expect(failCount).toBe(0)
await check(() => {
// we expect 3 images to load and for none of them to have errors
if (fulfilledCount === 3 && failCount === 0) {
return 'success'
}
}, 'success')
})

afterAll(async () => {
afterAll(() => {
proxyServer.close()
})
}
Expand Down

0 comments on commit 3e77d69

Please sign in to comment.