Skip to content

Commit

Permalink
Tests: next-image-legacy image loaded in static props
Browse files Browse the repository at this point in the history
  • Loading branch information
Laityned committed Oct 24, 2022
1 parent e3ac187 commit 3794f5e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion test/integration/next-image-legacy/default/pages/static-img.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import testImg from '../public/foo/test-rect.jpg'
import testImgProp from '../public/exif-rotation.jpg'
import Image from 'next/legacy/image'

import testJPG from '../public/test.jpg'
Expand All @@ -13,7 +14,11 @@ import testICO from '../public/test.ico'

import TallImage from '../components/TallImage'

const Page = () => {
export const getStaticProps = () => ({
props: { testImgProp },
})

const Page = ({ testImgProp }) => {
return (
<div>
<h1 id="page-header">Static Image</h1>
Expand All @@ -23,6 +28,12 @@ const Page = () => {
layout="fixed"
placeholder="blur"
/>
<Image
id="basic-staticprop"
src={testImgProp}
layout="fixed"
placeholder="blur"
/>
<TallImage />
<Image
id="defined-size-static"
Expand Down
22 changes: 22 additions & 0 deletions test/integration/next-image-legacy/default/test/static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ const runTests = () => {
`style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAOklEQVR42iWGsQkAIBDE0iuIdiLOJjiGIzjiL/Meb4okiNYIlLjK3hJMzCQG1/0qmXXOUkjAV+m9wAMe3QiV6Ne8VgAAAABJRU5ErkJggg==&quot;)`
)
})

it('should load direct imported image', async () => {
const src = await browser.elementById('basic-static').getAttribute('src')
expect(src).toMatch(
/_next\/image\?url=%2F_next%2Fstatic%2Fmedia%2Ftest-rect(.+)\.jpg&w=828&q=75/
)
const fullSrc = new URL(src, `http://localhost:${appPort}`)
const res = await fetch(fullSrc)
expect(res.status).toBe(200)
})

it('should load staticprops imported image', async () => {
const src = await browser
.elementById('basic-staticprop')
.getAttribute('src')
expect(src).toMatch(
/_next\/image\?url=%2F_next%2Fstatic%2Fmedia%2Fexif-rotation(.+)\.jpg&w=256&q=75/
)
const fullSrc = new URL(src, `http://localhost:${appPort}`)
const res = await fetch(fullSrc)
expect(res.status).toBe(200)
})
}

describe('Build Error Tests', () => {
Expand Down

0 comments on commit 3794f5e

Please sign in to comment.