Skip to content

Commit

Permalink
chore(test): add more tests for image optimizer formats
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed May 4, 2024
1 parent 9ec37c1 commit 6cc2596
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/integration/image-optimizer/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,57 @@ export function runTests(ctx) {
// FIXME: await expectWidth(res, ctx.w)
})

it('should resize gif (not animated)', async () => {
const query = { url: '/test.gif', w: ctx.w, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toBe('image/webp')
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isDev ? 0 : minimumCacheTTL}, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('etag')).toBeTruthy()
expect(res.headers.get('Content-Disposition')).toBe(
`${contentDispositionType}; filename="test.webp"`
)
await expectWidth(res, ctx.w)
})

it('should resize tiff', async () => {
const query = { url: '/test.tiff', w: ctx.w, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toBe('image/webp')
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isDev ? 0 : minimumCacheTTL}, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('etag')).toBeTruthy()
expect(res.headers.get('Content-Disposition')).toBe(
`${contentDispositionType}; filename="test.webp"`
)
await expectWidth(res, ctx.w)
})

it('should resize avif', async () => {
const query = { url: '/test.avif', w: ctx.w, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toBe('image/webp')
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isDev ? 0 : minimumCacheTTL}, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('etag')).toBeTruthy()
expect(res.headers.get('Content-Disposition')).toBe(
`${contentDispositionType}; filename="test.webp"`
)
await expectWidth(res, ctx.w)
})

it('should resize relative url and old Chrome accept header as webp', async () => {
const query = { url: '/test.png', w: ctx.w, q: 80 }
const opts = {
Expand Down Expand Up @@ -656,6 +707,23 @@ export function runTests(ctx) {
await expectWidth(res, ctx.w)
})

it('should resize avif and maintain format', async () => {
const query = { url: '/test.avif', w: ctx.w, q: 75 }
const opts = { headers: { accept: 'image/avif' } }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toBe('image/avif')
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isDev ? 0 : minimumCacheTTL}, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('etag')).toBeTruthy()
expect(res.headers.get('Content-Disposition')).toBe(
`${contentDispositionType}; filename="test.avif"`
)
await expectWidth(res, ctx.w)
})

it('should compress avif smaller than webp at q=100', async () => {
await expectAvifSmallerThanWebp(ctx.w, 100, ctx.appPort)
})
Expand Down

0 comments on commit 6cc2596

Please sign in to comment.