@@ -129,31 +129,37 @@ describe("Image optimizer", () => {
129129
130130 describe ( "Routes" , ( ) => {
131131 it . each `
132- imagePath | expectedObjectKey
133- ${ "/test-image.png" } | ${ "public/test-image.png" }
134- ${ "/static/test-image.png" } | ${ "static/test-image.png" }
135- ${ "/_next/static/test-image.png" } | ${ "_next/static/test-image.png" }
136- ` ( "serves image request" , async ( { imagePath, expectedObjectKey } ) => {
137- const { parsedUrl, req, res } = createEventByImagePath ( imagePath ) ;
138-
139- await imageOptimizer (
140- "" ,
141- imagesManifest as ImagesManifest ,
142- req ,
143- res ,
144- parsedUrl ,
145- mockPlatformClient as PlatformClient
146- ) ;
147-
148- expect ( res . getHeaders ( ) ) . toEqual ( {
149- "cache-control" : "public, max-age=60" ,
150- etag : expect . any ( String ) ,
151- "content-type" : "image/webp"
152- } ) ;
153- expect ( res . statusCode ) . toEqual ( 200 ) ;
154-
155- expect ( mockPlatformClient . getObject ) . toBeCalledWith ( expectedObjectKey ) ;
156- } ) ;
132+ imagePath | accept | expectedObjectKey
133+ ${ "/test-image.png" } | ${ "image/avif" } | ${ "public/test-image.png" }
134+ ${ "/test-image.png" } | ${ "image/webp" } | ${ "public/test-image.png" }
135+ ${ "/static/test-image.png" } | ${ "image/webp" } | ${ "static/test-image.png" }
136+ ${ "/_next/static/test-image.png" } | ${ "image/webp" } | ${ "_next/static/test-image.png" }
137+ ` (
138+ "serves image request" ,
139+ async ( { imagePath, accept, expectedObjectKey } ) => {
140+ const { parsedUrl, req, res } = createEventByImagePath ( imagePath , {
141+ accept : accept
142+ } ) ;
143+
144+ await imageOptimizer (
145+ "" ,
146+ imagesManifest as ImagesManifest ,
147+ req ,
148+ res ,
149+ parsedUrl ,
150+ mockPlatformClient as PlatformClient
151+ ) ;
152+
153+ expect ( res . getHeaders ( ) ) . toEqual ( {
154+ "cache-control" : "public, max-age=60" ,
155+ etag : expect . any ( String ) ,
156+ "content-type" : accept
157+ } ) ;
158+ expect ( res . statusCode ) . toEqual ( 200 ) ;
159+
160+ expect ( mockPlatformClient . getObject ) . toBeCalledWith ( expectedObjectKey ) ;
161+ }
162+ ) ;
157163
158164 it . each `
159165 imagePath
0 commit comments