Unverified Commit cf0cec1b authored by Steven's avatar Steven Committed by GitHub

chore(test): add more tests for image optimizer formats (#65363)

There were a few cases that were untested so I added new tests to cover
them.

Closes NEXT-3322
parent 581fb0c9
......@@ -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 = {
......@@ -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)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment