Skip to content

Commit

Permalink
chore(test): test image preload below the fold (#65528)
Browse files Browse the repository at this point in the history
Follow up to #65058 to ensure
preloads work below the fold.

Closes NEXT-3364
  • Loading branch information
styfle committed May 9, 2024
1 parent 067eac6 commit 01db985
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/integration/next-image-legacy/default/pages/priority.js
Expand Up @@ -60,6 +60,15 @@ const Page = () => {
layout="responsive"
/>
<p id="stubtext">This is the priority page</p>
<div style={{ height: '1000vh' }} />
<Image
priority
id="belowthefold"
src="/test.tiff"
width="400"
height="400"
alt=""
/>
</div>
)
}
Expand Down
8 changes: 8 additions & 0 deletions test/integration/next-image-legacy/default/test/index.test.ts
Expand Up @@ -146,6 +146,11 @@ function runTests(mode) {
imagesrcset:
'/_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',
},
{
imagesizes: '',
imagesrcset:
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x',
},
])

// When priority={true}, we should _not_ set loading="lazy"
Expand All @@ -171,6 +176,9 @@ function runTests(mode) {
expect(
await browser.elementById('responsive2').getAttribute('loading')
).toBe(null)
expect(
await browser.elementById('belowthefold').getAttribute('loading')
).toBe(null)

const warnings = (await browser.log())
.map((log) => log.message)
Expand Down
9 changes: 9 additions & 0 deletions test/integration/next-image-new/app-dir/app/priority/page.js
Expand Up @@ -66,6 +66,15 @@ const Page = () => {
fetchPriority="low"
/>
<p id="stubtext">This is the priority page</p>
<div style={{ height: '1000vh' }} />
<Image
priority
id="belowthefold"
src="/test.tiff"
width="400"
height="400"
alt=""
/>
</div>
)
}
Expand Down
22 changes: 22 additions & 0 deletions test/integration/next-image-new/app-dir/test/index.test.ts
Expand Up @@ -180,6 +180,21 @@ function runTests(mode) {
referrerpolicy: 'no-referrer',
})

expect(
entries.find(
(item) =>
item.imagesrcset ===
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x'
)
).toEqual({
fetchpriority: 'high',
imagesizes: '',
imagesrcset:
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x',
crossorigin: '',
referrerpolicy: '',
})

// When priority={true}, we should _not_ set loading="lazy"
expect(
await browser.elementById('basic-image').getAttribute('loading')
Expand Down Expand Up @@ -216,6 +231,13 @@ function runTests(mode) {
'lazy'
)

expect(
await browser.elementById('belowthefold').getAttribute('fetchpriority')
).toBe('high')
expect(
await browser.elementById('belowthefold').getAttribute('loading')
).toBe(null)

const warnings = (await browser.log('browser'))
.map((log) => log.message)
.join('\n')
Expand Down
9 changes: 9 additions & 0 deletions test/integration/next-image-new/default/pages/priority.js
Expand Up @@ -66,6 +66,15 @@ const Page = () => {
fetchPriority="low"
/>
<p id="stubtext">This is the priority page</p>
<div style={{ height: '1000vh' }} />
<Image
priority
id="belowthefold"
src="/test.tiff"
width="400"
height="400"
alt=""
/>
</div>
)
}
Expand Down
22 changes: 22 additions & 0 deletions test/integration/next-image-new/default/test/index.test.ts
Expand Up @@ -181,6 +181,21 @@ function runTests(mode) {
referrerpolicy: 'no-referrer',
})

expect(
entries.find(
(item) =>
item.imagesrcset ===
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x'
)
).toEqual({
fetchpriority: 'high',
imagesizes: '',
imagesrcset:
'/_next/image?url=%2Ftest.tiff&w=640&q=75 1x, /_next/image?url=%2Ftest.tiff&w=828&q=75 2x',
crossorigin: '',
referrerpolicy: '',
})

// When priority={true}, we should _not_ set loading="lazy"
expect(
await browser.elementById('basic-image').getAttribute('loading')
Expand Down Expand Up @@ -217,6 +232,13 @@ function runTests(mode) {
'lazy'
)

expect(
await browser.elementById('belowthefold').getAttribute('fetchpriority')
).toBe('high')
expect(
await browser.elementById('belowthefold').getAttribute('loading')
).toBe(null)

const warnings = (await browser.log('browser'))
.map((log) => log.message)
.join('\n')
Expand Down

0 comments on commit 01db985

Please sign in to comment.