@@ -373,6 +373,18 @@ describe('send(ctx, file)', function () {
373
373
} )
374
374
375
375
describe ( 'or .br version when requested and if possible' , function ( ) {
376
+ function parser ( res , cb ) {
377
+ const chunks = [ ]
378
+ res . on ( 'data' , chunk => {
379
+ chunks . push ( chunk )
380
+ } )
381
+ res . on ( 'end' , ( ) => {
382
+ decompress ( Buffer . concat ( chunks ) , ( err , data ) => {
383
+ cb ( err , data . toString ( ) )
384
+ } )
385
+ } )
386
+ }
387
+
376
388
it ( 'should return path' , function ( done ) {
377
389
const app = new Koa ( )
378
390
@@ -397,15 +409,13 @@ describe('send(ctx, file)', function () {
397
409
398
410
request ( app . listen ( ) )
399
411
. get ( '/' )
412
+ . parse ( parser )
400
413
. set ( 'Accept-Encoding' , 'br, deflate, identity' )
401
414
. expect ( 'Content-Length' , '22' )
402
415
. expect ( 200 )
403
416
. then ( ( { body} ) => {
404
- decompress ( body , ( err , output ) => {
405
- assert . strictEqual ( err , null )
406
- assert . deepStrictEqual ( output . toString ( ) , '{ "name": "tobi" }' )
407
- done ( )
408
- } )
417
+ assert . deepStrictEqual ( body , '{ "name": "tobi" }' )
418
+ done ( )
409
419
} )
410
420
} )
411
421
@@ -418,15 +428,13 @@ describe('send(ctx, file)', function () {
418
428
419
429
request ( app . listen ( ) )
420
430
. get ( '/' )
431
+ . parse ( parser )
421
432
. set ( 'Accept-Encoding' , 'br, deflate, identity' )
422
433
. expect ( 'Content-Length' , '22' )
423
434
. expect ( 200 )
424
435
. then ( ( { body} ) => {
425
- decompress ( body , ( err , output ) => {
426
- assert . strictEqual ( err , null )
427
- assert . deepStrictEqual ( output . toString ( ) , '{ "name": "tobi" }' )
428
- done ( )
429
- } )
436
+ assert . deepStrictEqual ( body , '{ "name": "tobi" }' )
437
+ done ( )
430
438
} )
431
439
} )
432
440
0 commit comments