Skip to content

Commit

Permalink
test: add next/image to static export fixture and test
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Jul 30, 2024
1 parent 367c396 commit 3f490f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/e2e/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ test('Renders the Home page correctly with output export and custom dist dir', a

await expectImageWasLoaded(page.locator('img'))
})

test.describe('next/image is using Netlify Image CDN', () => {
test('Local images', async ({ page, outputExport }) => {
const nextImageResponsePromise = page.waitForResponse('**/_next/image**')

await page.goto(`${outputExport.url}/image/local`)

const nextImageResponse = await nextImageResponsePromise
expect(nextImageResponse.request().url()).toContain('_next/image?url=%2Fsquirrel.jpg')

expect(nextImageResponse.status()).toBe(200)
// ensure next/image is using Image CDN
// source image is jpg, but when requesting it through Image CDN avif will be returned
expect(await nextImageResponse.headerValue('content-type')).toEqual('image/avif')

await expectImageWasLoaded(page.locator('img'))
})
})
10 changes: 10 additions & 0 deletions tests/fixtures/output-export/app/image/local/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Image from 'next/image'

export default function NextImageUsingNetlifyImageCDN() {
return (
<main>
<h1>Next/Image + Netlify Image CDN</h1>
<Image src="/squirrel.jpg" alt="a cute squirrel (next/image)" width={300} height={278} />
</main>
)
}

0 comments on commit 3f490f6

Please sign in to comment.