Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Page = () => {
return (
<div>
<h1 id="page-header">Static Image</h1>
<Image id="basic-static" src={testImg} placeholder="blur" />
<Image id="basic-static" src={testImg} placeholder="blur" priority />
<TallImage />
<Image
id="defined-width-and-height"
Expand Down
24 changes: 24 additions & 0 deletions test/integration/next-image-new/app-dir/test/static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ const runTests = (isDev) => {
)
})
}
it('should have <head> containing <meta name="viewport"> followed by <link rel="preload"> for priority image', async () => {
let metaViewport = { index: 0, attribs: {} as any }
let linkPreload = { index: 0, attribs: {} as any }
$('head')
.children()
.toArray()
.forEach((child, index) => {
const { tagName, attribs } = child
if (tagName === 'meta' && attribs.name === 'viewport') {
metaViewport = { index, attribs }
} else if (
tagName === 'link' &&
attribs.rel === 'preload' &&
attribs.as === 'image'
) {
linkPreload = { index, attribs }
}
})
expect(metaViewport.attribs.content).toContain('width=device-width')
expect(linkPreload.attribs.imagesrcset).toContain(
'%2F_next%2Fstatic%2Fmedia%2Ftest-rect.f323a148.jpg'
)
expect(metaViewport.index).toBeLessThan(linkPreload.index)
})
it('Should automatically provide an image height and width', async () => {
const img = $('#basic-non-static')
expect(img.attr('width')).toBe('400')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Page = () => {
return (
<div>
<h1 id="page-header">Static Image</h1>
<Image id="basic-static" src={testImg} placeholder="blur" />
<Image id="basic-static" src={testImg} placeholder="blur" priority />
<TallImage />
<Image
id="defined-width-and-height"
Expand Down
24 changes: 24 additions & 0 deletions test/integration/next-image-new/base-path/test/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ const runTests = (isDev) => {
)
})
}
it('should have <head> containing <meta name="viewport"> followed by <link rel="preload"> for priority image', async () => {
let metaViewport = { index: 0, attribs: {} }
let linkPreload = { index: 0, attribs: {} }
$('head')
.children()
.toArray()
.forEach((child, index) => {
const { tagName, attribs } = child
if (tagName === 'meta' && attribs.name === 'viewport') {
metaViewport = { index, attribs }
} else if (
tagName === 'link' &&
attribs.rel === 'preload' &&
attribs.as === 'image'
) {
linkPreload = { index, attribs }
}
})
expect(metaViewport.attribs.content).toContain('width=device-width')
expect(linkPreload.attribs.imagesrcset).toContain(
'%2F_next%2Fstatic%2Fmedia%2Ftest-rect.f323a148.jpg'
)
expect(metaViewport.index).toBeLessThan(linkPreload.index)
})
it('Should automatically provide an image height and width', async () => {
const img = $('#basic-non-static')
expect(img.attr('width')).toBe('400')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Page = ({ testImgProp }) => {
return (
<div>
<h1 id="page-header">Static Image</h1>
<Image id="basic-static" src={testImg} placeholder="blur" />
<Image id="basic-static" src={testImg} placeholder="blur" priority />
<Image id="basic-staticprop" src={testImgProp} placeholder="blur" />
<TallImage />
<Image
Expand Down
24 changes: 24 additions & 0 deletions test/integration/next-image-new/default/test/static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ const runTests = (isDev) => {
)
})
}
it('should have <head> containing <meta name="viewport"> followed by <link rel="preload"> for priority image', async () => {
let metaViewport = { index: 0, attribs: {} as any }
let linkPreload = { index: 0, attribs: {} as any }
$('head')
.children()
.toArray()
.forEach((child, index) => {
const { tagName, attribs } = child
if (tagName === 'meta' && attribs.name === 'viewport') {
metaViewport = { index, attribs }
} else if (
tagName === 'link' &&
attribs.rel === 'preload' &&
attribs.as === 'image'
) {
linkPreload = { index, attribs }
}
})
expect(metaViewport.attribs.content).toContain('width=device-width')
expect(linkPreload.attribs.imagesrcset).toContain(
'%2F_next%2Fstatic%2Fmedia%2Ftest-rect.f323a148.jpg'
)
expect(metaViewport.index).toBeLessThan(linkPreload.index)
})
it('Should automatically provide an image height and width', async () => {
const img = $('#basic-non-static')
expect(img.attr('width')).toBe('400')
Expand Down