Skip to content

Commit d32121b

Browse files
authored
chore(test): test remote image from proxy (#56895)
This PR adds a test to ensure we don't regress again when using proxies in front of Next.js with `connection: 'upgrade'`. - Regression introduced in #56226 - Issue reported in #56038 - Rolled back in #56836
1 parent 3e77d69 commit d32121b

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

test/e2e/app-dir/next-image/app/page.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export default function Page() {
77
<>
88
<h2>app-page</h2>
99
<Image id="app-page" src={testPng} quality={90} />
10+
<Image
11+
id="remote-app-page"
12+
src="https://image-optimization-test.vercel.app/test.jpg"
13+
width="200"
14+
height="200"
15+
quality={90}
16+
/>
1017
<Comp />
1118
</>
1219
)

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,34 @@ createNextDescribe(
7373
},
7474
})
7575

76-
const image = browser.elementByCss('#app-page')
77-
const src = await image.getAttribute('src')
78-
79-
expect(src).toContain(
76+
const local = await browser.elementByCss('#app-page').getAttribute('src')
77+
expect(local).toContain(
8078
'/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.3f1a293b.png&w=828&q=90'
8179
)
8280

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+
const remote = await browser
82+
.elementByCss('#remote-app-page')
83+
.getAttribute('src')
84+
expect(remote).toBe(
85+
'/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2Ftest.jpg&w=640&q=90'
86+
)
87+
88+
const expected = JSON.stringify({ fulfilledCount: 4, failCount: 0 })
89+
await check(() => JSON.stringify({ fulfilledCount, failCount }), expected)
90+
})
91+
92+
it('should work with connection upgrade by removing it via filterReqHeaders()', async () => {
93+
const opts = { headers: { connection: 'upgrade' } }
94+
const res1 = await next.fetch(
95+
'/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.3f1a293b.png&w=828&q=90',
96+
opts
97+
)
98+
expect(res1.status).toBe(200)
99+
const res2 = await next.fetch(
100+
'/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2Ftest.jpg&w=640&q=90',
101+
opts
102+
)
103+
expect(res2.status).toBe(200)
89104
})
90105

91106
afterAll(() => {
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
module.exports = {}
1+
module.exports = {
2+
images: {
3+
remotePatterns: [{ hostname: 'image-optimization-test.vercel.app' }],
4+
},
5+
}

0 commit comments

Comments
 (0)