@@ -537,6 +537,96 @@ describe('inject()', () => {
537537 } ) ;
538538 expect ( res . payload . toString ( ) ) . to . equal ( body . toString ( ) ) ;
539539 } ) ;
540+
541+ it ( 'returns aborted on immediate res.destroy()' , async ( ) => {
542+
543+ const dispatch = function ( req , res ) {
544+
545+ res . destroy ( ) ;
546+ } ;
547+
548+ const res = await Shot . inject ( dispatch , { method : 'get' , url : '/' } ) ;
549+ expect ( res . aborted ) . to . be . true ( ) ;
550+ expect ( res . statusCode ) . to . equal ( 499 ) ;
551+ expect ( res . raw . res . errored ) . to . not . exist ( ) ;
552+ } ) ;
553+
554+ it ( 'returns aborted on immediate res.destroy(error)' , async ( ) => {
555+
556+ const dispatch = function ( req , res ) {
557+
558+ res . destroy ( new Error ( 'stop' ) ) ;
559+ } ;
560+
561+ const res = await Shot . inject ( dispatch , { method : 'get' , url : '/' } ) ;
562+ expect ( res . aborted ) . to . be . true ( ) ;
563+ expect ( res . statusCode ) . to . equal ( 499 ) ;
564+ expect ( res . raw . res . errored ) . to . be . an . error ( 'stop' ) ;
565+ } ) ;
566+
567+ it ( 'returns aborted on res.destroy() while transmitting payload' , async ( ) => {
568+
569+ const dispatch = function ( req , res ) {
570+
571+ res . writeHead ( 404 ) ;
572+ res . write ( 'data' ) ;
573+ setTimeout ( ( ) => res . destroy ( ) , 1 ) ;
574+ } ;
575+
576+ const res = await Shot . inject ( dispatch , { method : 'get' , url : '/' } ) ;
577+ expect ( res . aborted ) . to . be . true ( ) ;
578+ expect ( res . statusCode ) . to . equal ( 404 ) ;
579+ expect ( res . raw . res . errored ) . to . not . exist ( ) ;
580+ expect ( res . payload ) . to . equal ( 'data' ) ;
581+ } ) ;
582+
583+ it ( 'returns aborted on res.destroy(error) while transmitting payload' , async ( ) => {
584+
585+ const dispatch = function ( req , res ) {
586+
587+ res . writeHead ( 404 ) ;
588+ res . write ( 'data' ) ;
589+ setTimeout ( ( ) => res . destroy ( new Error ( 'stop' ) ) , 1 ) ;
590+ } ;
591+
592+ const res = await Shot . inject ( dispatch , { method : 'get' , url : '/' } ) ;
593+ expect ( res . aborted ) . to . be . true ( ) ;
594+ expect ( res . statusCode ) . to . equal ( 404 ) ;
595+ expect ( res . raw . res . errored ) . to . be . an . error ( 'stop' ) ;
596+ expect ( res . payload ) . to . equal ( 'data' ) ;
597+ } ) ;
598+
599+ it ( 'handles res.destroy() after transmitting payload' , async ( ) => {
600+
601+ const dispatch = function ( req , res ) {
602+
603+ res . writeHead ( 404 ) ;
604+ res . end ( 'data' ) ;
605+ res . destroy ( ) ;
606+ } ;
607+
608+ const res = await Shot . inject ( dispatch , { method : 'get' , url : '/' } ) ;
609+ expect ( res . aborted ) . to . not . exist ( ) ;
610+ expect ( res . statusCode ) . to . equal ( 404 ) ;
611+ expect ( res . raw . res . errored ) . to . not . exist ( ) ;
612+ expect ( res . payload ) . to . equal ( 'data' ) ;
613+ } ) ;
614+
615+ it ( 'handles res.destroy(error) after transmitting payload' , async ( ) => {
616+
617+ const dispatch = function ( req , res ) {
618+
619+ res . writeHead ( 404 ) ;
620+ res . end ( 'data' ) ;
621+ res . destroy ( new Error ( 'stop' ) ) ;
622+ } ;
623+
624+ const res = await Shot . inject ( dispatch , { method : 'get' , url : '/' } ) ;
625+ expect ( res . aborted ) . to . not . exist ( ) ;
626+ expect ( res . statusCode ) . to . equal ( 404 ) ;
627+ expect ( res . raw . res . errored ) . to . be . an . error ( 'stop' ) ;
628+ expect ( res . payload ) . to . equal ( 'data' ) ;
629+ } ) ;
540630} ) ;
541631
542632describe ( 'writeHead()' , ( ) => {
0 commit comments