Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve next-image-proxy test #56893

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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