Skip to content

Commit

Permalink
tweak next image proxy test
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Oct 16, 2023
1 parent 1609da2 commit 9f5d292
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 9f5d292

Please sign in to comment.