diff --git a/test/integration/next-image-new/app-dir/app/static-img/page.js b/test/integration/next-image-new/app-dir/app/static-img/page.js index 92b10404cfdb3..21d23dc76edd5 100644 --- a/test/integration/next-image-new/app-dir/app/static-img/page.js +++ b/test/integration/next-image-new/app-dir/app/static-img/page.js @@ -23,7 +23,7 @@ const Page = () => { return (

Static Image

- + { ) }) } + it('should have containing followed by 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') diff --git a/test/integration/next-image-new/base-path/pages/static-img.js b/test/integration/next-image-new/base-path/pages/static-img.js index fc2cfee474650..f3c230267bb65 100644 --- a/test/integration/next-image-new/base-path/pages/static-img.js +++ b/test/integration/next-image-new/base-path/pages/static-img.js @@ -18,7 +18,7 @@ const Page = () => { return (

Static Image

- + { ) }) } + it('should have containing followed by 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') diff --git a/test/integration/next-image-new/default/pages/static-img.js b/test/integration/next-image-new/default/pages/static-img.js index 3108954cfcb43..c57e8fa3461a4 100644 --- a/test/integration/next-image-new/default/pages/static-img.js +++ b/test/integration/next-image-new/default/pages/static-img.js @@ -28,7 +28,7 @@ const Page = ({ testImgProp }) => { return (

Static Image

- + { ) }) } + it('should have containing followed by 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')