From 6cc25964e313a4648171448228d69d8a33b4c398 Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 4 May 2024 16:25:19 -0400 Subject: [PATCH] chore(test): add more tests for image optimizer formats --- test/integration/image-optimizer/test/util.ts | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/integration/image-optimizer/test/util.ts b/test/integration/image-optimizer/test/util.ts index 255b9cdebc8e3..ef5ed4c8da42b 100644 --- a/test/integration/image-optimizer/test/util.ts +++ b/test/integration/image-optimizer/test/util.ts @@ -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) })