Skip to content

Commit 01db985

Browse files
authored
chore(test): test image preload below the fold (#65528)
Follow up to #65058 to ensure preloads work below the fold. Closes NEXT-3364
1 parent 067eac6 commit 01db985

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

test/integration/next-image-legacy/default/pages/priority.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ const Page = () => {
6060
layout="responsive"
6161
/>
6262
<p id="stubtext">This is the priority page</p>
63+
<div style={{ height: '1000vh' }} />
64+
<Image
65+
priority
66+
id="belowthefold"
67+
src="/test.tiff"
68+
width="400"
69+
height="400"
70+
alt=""
71+
/>
6372
</div>
6473
)
6574
}

test/integration/next-image-legacy/default/test/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ function runTests(mode) {
146146
imagesrcset:
147147
'/_next/image?url=%2Fwide.png&w=640&q=75 640w, /_next/image?url=%2Fwide.png&w=750&q=75 750w, /_next/image?url=%2Fwide.png&w=828&q=75 828w, /_next/image?url=%2Fwide.png&w=1080&q=75 1080w, /_next/image?url=%2Fwide.png&w=1200&q=75 1200w, /_next/image?url=%2Fwide.png&w=1920&q=75 1920w, /_next/image?url=%2Fwide.png&w=2048&q=75 2048w, /_next/image?url=%2Fwide.png&w=3840&q=75 3840w',
148148
},
149+
{
150+
imagesizes: '',
151+
imagesrcset:
152+
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x',
153+
},
149154
])
150155

151156
// When priority={true}, we should _not_ set loading="lazy"
@@ -171,6 +176,9 @@ function runTests(mode) {
171176
expect(
172177
await browser.elementById('responsive2').getAttribute('loading')
173178
).toBe(null)
179+
expect(
180+
await browser.elementById('belowthefold').getAttribute('loading')
181+
).toBe(null)
174182

175183
const warnings = (await browser.log())
176184
.map((log) => log.message)

test/integration/next-image-new/app-dir/app/priority/page.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ const Page = () => {
6666
fetchPriority="low"
6767
/>
6868
<p id="stubtext">This is the priority page</p>
69+
<div style={{ height: '1000vh' }} />
70+
<Image
71+
priority
72+
id="belowthefold"
73+
src="/test.tiff"
74+
width="400"
75+
height="400"
76+
alt=""
77+
/>
6978
</div>
7079
)
7180
}

test/integration/next-image-new/app-dir/test/index.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ function runTests(mode) {
180180
referrerpolicy: 'no-referrer',
181181
})
182182

183+
expect(
184+
entries.find(
185+
(item) =>
186+
item.imagesrcset ===
187+
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x'
188+
)
189+
).toEqual({
190+
fetchpriority: 'high',
191+
imagesizes: '',
192+
imagesrcset:
193+
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x',
194+
crossorigin: '',
195+
referrerpolicy: '',
196+
})
197+
183198
// When priority={true}, we should _not_ set loading="lazy"
184199
expect(
185200
await browser.elementById('basic-image').getAttribute('loading')
@@ -216,6 +231,13 @@ function runTests(mode) {
216231
'lazy'
217232
)
218233

234+
expect(
235+
await browser.elementById('belowthefold').getAttribute('fetchpriority')
236+
).toBe('high')
237+
expect(
238+
await browser.elementById('belowthefold').getAttribute('loading')
239+
).toBe(null)
240+
219241
const warnings = (await browser.log('browser'))
220242
.map((log) => log.message)
221243
.join('\n')

test/integration/next-image-new/default/pages/priority.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ const Page = () => {
6666
fetchPriority="low"
6767
/>
6868
<p id="stubtext">This is the priority page</p>
69+
<div style={{ height: '1000vh' }} />
70+
<Image
71+
priority
72+
id="belowthefold"
73+
src="/test.tiff"
74+
width="400"
75+
height="400"
76+
alt=""
77+
/>
6978
</div>
7079
)
7180
}

test/integration/next-image-new/default/test/index.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ function runTests(mode) {
181181
referrerpolicy: 'no-referrer',
182182
})
183183

184+
expect(
185+
entries.find(
186+
(item) =>
187+
item.imagesrcset ===
188+
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x'
189+
)
190+
).toEqual({
191+
fetchpriority: 'high',
192+
imagesizes: '',
193+
imagesrcset:
194+
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x',
195+
crossorigin: '',
196+
referrerpolicy: '',
197+
})
198+
184199
// When priority={true}, we should _not_ set loading="lazy"
185200
expect(
186201
await browser.elementById('basic-image').getAttribute('loading')
@@ -217,6 +232,13 @@ function runTests(mode) {
217232
'lazy'
218233
)
219234

235+
expect(
236+
await browser.elementById('belowthefold').getAttribute('fetchpriority')
237+
).toBe('high')
238+
expect(
239+
await browser.elementById('belowthefold').getAttribute('loading')
240+
).toBe(null)
241+
220242
const warnings = (await browser.log('browser'))
221243
.map((log) => log.message)
222244
.join('\n')

0 commit comments

Comments
 (0)