@@ -681,18 +681,44 @@ describe('compression()', function () {
681681 it ( 'should call the passed callbacks in the order passed when compressing' , function ( done ) {
682682 var hasCallbacks = false
683683 var callbackOutput = [ ]
684+ var errorsCaught = 0
684685 var server = createServer ( null , function ( req , res ) {
685686 hasCallbacks = ( http . OutgoingMessage . prototype . write . length === 3 && http . OutgoingMessage . prototype . end . length === 3 )
686687 res . setHeader ( 'Content-Type' , 'text/plain' )
687- res . write ( 'Hello' , null , function ( ) {
688- callbackOutput . push ( 0 )
689- } )
690- res . write ( ' World' , null , function ( ) {
691- callbackOutput . push ( 1 )
692- } )
693- res . end ( null , null , function ( ) {
694- callbackOutput . push ( 2 )
695- } )
688+ try {
689+ res . write ( 'Hello' , null , function ( ) {
690+ callbackOutput . push ( 0 )
691+ } )
692+ } catch ( error ) {
693+ errorsCaught ++
694+ if ( hasCallbacks || error . message !== "compression, request.write does not support callback" ) {
695+ throw error ;
696+ }
697+ res . write ( 'Hello' ) ;
698+ }
699+ try {
700+ res . write ( ' World' , null , function ( ) {
701+ callbackOutput . push ( 1 )
702+ } )
703+ } catch ( error ) {
704+ errorsCaught ++
705+ if ( hasCallbacks || error . message !== "compression, request.write does not support callback" ) {
706+ throw error ;
707+ }
708+ res . write ( ' World' )
709+ }
710+ try {
711+ res . end ( null , null , function ( ) {
712+ callbackOutput . push ( 2 )
713+ } )
714+ } catch ( error ) {
715+ errorsCaught ++
716+ console . log ( error )
717+ if ( hasCallbacks || error . message !== "compression, request.end does not support callback" ) {
718+ throw error ;
719+ }
720+ res . end ( )
721+ }
696722 } )
697723
698724 request ( server )
@@ -709,6 +735,7 @@ describe('compression()', function () {
709735 } else {
710736 // nodejs 0.10 zlib has callbacks but OutgoingMessage doesn't, assert that no callbacks were made
711737 assert . equal ( callbackOutput . length , 0 )
738+ assert . equal ( errorsCaught , 3 )
712739 }
713740 done ( )
714741 } )
@@ -717,19 +744,44 @@ describe('compression()', function () {
717744 it ( 'should call the passed callbacks in the order passed when not compressing' , function ( done ) {
718745 var hasCallbacks = false
719746 var callbackOutput = [ ]
747+ var errorsCaught = 0
720748 var server = createServer ( null , function ( req , res ) {
721749 hasCallbacks = ( http . OutgoingMessage . prototype . write . length === 3 && http . OutgoingMessage . prototype . end . length === 3 )
722750 res . setHeader ( 'Cache-Control' , 'no-transform' )
723751 res . setHeader ( 'Content-Type' , 'text/plain' )
724- res . write ( 'hello,' , null , function ( ) {
725- callbackOutput . push ( 0 )
726- } )
727- res . write ( ' world' , null , function ( ) {
728- callbackOutput . push ( 1 )
729- } )
730- res . end ( null , null , function ( ) {
731- callbackOutput . push ( 2 )
732- } )
752+ try {
753+ res . write ( 'hello,' , null , function ( ) {
754+ callbackOutput . push ( 0 )
755+ } )
756+ } catch ( error ) {
757+ errorsCaught ++
758+ if ( hasCallbacks || error . message !== "compression, request.write does not support callback" ) {
759+ throw error ;
760+ }
761+ res . write ( 'Hello' ) ;
762+ }
763+ try {
764+ res . write ( ' world' , null , function ( ) {
765+ callbackOutput . push ( 1 )
766+ } )
767+ } catch ( error ) {
768+ errorsCaught ++
769+ if ( hasCallbacks || error . message !== "compression, request.write does not support callback" ) {
770+ throw error ;
771+ }
772+ res . write ( ' world' ) ;
773+ }
774+ try {
775+ res . end ( null , null , function ( ) {
776+ callbackOutput . push ( 2 )
777+ } )
778+ } catch ( error ) {
779+ errorsCaught ++
780+ if ( hasCallbacks || error . message !== "compression, request.end does not support callback" ) {
781+ throw error ;
782+ }
783+ res . end ( ) ;
784+ }
733785 } )
734786
735787 request ( server )
@@ -746,6 +798,7 @@ describe('compression()', function () {
746798 assert . deepEqual ( callbackOutput , [ 0 , 1 , 2 ] )
747799 } else {
748800 assert . equal ( callbackOutput . length , 0 )
801+ assert . equal ( errorsCaught , 3 )
749802 }
750803 done ( )
751804 } )
0 commit comments