@@ -70,10 +70,13 @@ export async function fsToJson(dir, output = {}) {
70
70
return output
71
71
}
72
72
73
- export async function expectWidth ( res , w ) {
73
+ export async function expectWidth ( res , w , { expectAnimated = false } = { } ) {
74
74
const buffer = await res . buffer ( )
75
75
const d = sizeOf ( buffer )
76
76
expect ( d . width ) . toBe ( w )
77
+ const lengthStr = res . headers . get ( 'Content-Length' )
78
+ expect ( lengthStr ) . toBe ( Buffer . byteLength ( buffer ) . toString ( ) )
79
+ expect ( isAnimated ( buffer ) ) . toBe ( expectAnimated )
77
80
}
78
81
79
82
export const cleanImagesDir = async ( ctx ) => {
@@ -170,7 +173,7 @@ export function runTests(ctx) {
170
173
expect ( res . headers . get ( 'Content-Disposition' ) ) . toBe (
171
174
`inline; filename="animated.gif"`
172
175
)
173
- expect ( isAnimated ( await res . buffer ( ) ) ) . toBe ( true )
176
+ await expectWidth ( res , 50 , { expectAnimated : true } )
174
177
} )
175
178
176
179
it ( 'should maintain animated png' , async ( ) => {
@@ -186,7 +189,7 @@ export function runTests(ctx) {
186
189
expect ( res . headers . get ( 'Content-Disposition' ) ) . toBe (
187
190
`inline; filename="animated.png"`
188
191
)
189
- expect ( isAnimated ( await res . buffer ( ) ) ) . toBe ( true )
192
+ await expectWidth ( res , 100 , { expectAnimated : true } )
190
193
} )
191
194
192
195
it ( 'should maintain animated png 2' , async ( ) => {
@@ -202,7 +205,7 @@ export function runTests(ctx) {
202
205
expect ( res . headers . get ( 'Content-Disposition' ) ) . toBe (
203
206
`inline; filename="animated2.png"`
204
207
)
205
- expect ( isAnimated ( await res . buffer ( ) ) ) . toBe ( true )
208
+ await expectWidth ( res , 1105 , { expectAnimated : true } )
206
209
} )
207
210
208
211
it ( 'should maintain animated webp' , async ( ) => {
@@ -218,7 +221,7 @@ export function runTests(ctx) {
218
221
expect ( res . headers . get ( 'Content-Disposition' ) ) . toBe (
219
222
`inline; filename="animated.webp"`
220
223
)
221
- expect ( isAnimated ( await res . buffer ( ) ) ) . toBe ( true )
224
+ await expectWidth ( res , 400 , { expectAnimated : true } )
222
225
} )
223
226
224
227
if ( ctx . dangerouslyAllowSVG ) {
@@ -227,6 +230,7 @@ export function runTests(ctx) {
227
230
const opts = { headers : { accept : 'image/webp' } }
228
231
const res = await fetchViaHTTP ( ctx . appPort , '/_next/image' , query , opts )
229
232
expect ( res . status ) . toBe ( 200 )
233
+ expect ( res . headers . get ( 'Content-Length' ) ) . toBe ( '603' )
230
234
expect ( res . headers . get ( 'Content-Type' ) ) . toContain ( 'image/svg+xml' )
231
235
expect ( res . headers . get ( 'Cache-Control' ) ) . toBe (
232
236
`public, max-age=0, must-revalidate`
@@ -329,6 +333,7 @@ export function runTests(ctx) {
329
333
expect ( res . headers . get ( 'Content-Disposition' ) ) . toBe (
330
334
`inline; filename="test.jpeg"`
331
335
)
336
+ await expectWidth ( res , ctx . w )
332
337
} )
333
338
334
339
if ( ! ctx . isOutdatedSharp ) {
@@ -348,6 +353,7 @@ export function runTests(ctx) {
348
353
expect ( res . headers . get ( 'Content-Disposition' ) ) . toBe (
349
354
`inline; filename="test.jpeg"`
350
355
)
356
+ await expectWidth ( res , ctx . w )
351
357
} )
352
358
}
353
359
0 commit comments