Skip to content

Commit

Permalink
Tests for image import in static props
Browse files Browse the repository at this point in the history
  • Loading branch information
Laityned committed Oct 24, 2022
1 parent c202004 commit e3ac187
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/integration/next-image-new/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/image'

import testJPG from '../public/test.jpg'
Expand All @@ -19,11 +20,16 @@ import TallImage from '../components/TallImage'
const blurDataURL =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNM/s/wBwAFjwJgf8HDLgAAAABJRU5ErkJggg=='

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

const Page = ({ testImgProp }) => {
return (
<div>
<h1 id="page-header">Static Image</h1>
<Image id="basic-static" src={testImg} placeholder="blur" />
<Image id="basic-staticprop" src={testImgProp} placeholder="blur" />
<TallImage />
<Image
id="defined-width-and-height"
Expand Down
22 changes: 22 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 @@ -142,6 +142,28 @@ const runTests = (isDev) => {
`color:transparent;background-size:cover;background-position:50% 50%;background-repeat:no-repeat;background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http%3A//www.w3.org/2000/svg' viewBox='0 0 100 200'%3E%3Cfilter id='b' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20'/%3E%3C/filter%3E%3Cimage preserveAspectRatio='none' filter='url(%23b)' x='0' y='0' height='100%25' width='100%25' href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNM/s/wBwAFjwJgf8HDLgAAAABJRU5ErkJggg=='/%3E%3C/svg%3E")`
)
})

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 e3ac187

Please sign in to comment.