@@ -795,6 +795,84 @@ describe("HttpConnection", () => {
795
795
} ) ;
796
796
} ) ;
797
797
798
+ it ( "transport handlers set before start" , async ( ) => {
799
+ await VerifyLogger . run ( async ( logger ) => {
800
+ const availableTransport = { transport : "LongPolling" , transferFormats : [ "Text" ] } ;
801
+ let handlersSet = false ;
802
+
803
+ let httpClientGetCount = 0 ;
804
+ const options : IHttpConnectionOptions = {
805
+ ...commonOptions ,
806
+ httpClient : new TestHttpClient ( )
807
+ . on ( "POST" , ( ) => ( { connectionId : "42" , availableTransports : [ availableTransport ] } ) )
808
+ . on ( "GET" , ( ) => {
809
+ httpClientGetCount ++ ;
810
+ if ( httpClientGetCount === 1 ) {
811
+ if ( ( connection as any ) . transport . onreceive && ( connection as any ) . transport . onclose ) {
812
+ handlersSet = true ;
813
+ }
814
+ // First long polling request must succeed so start completes
815
+ return "" ;
816
+ }
817
+ } )
818
+ . on ( "DELETE" , ( ) => new HttpResponse ( 202 ) ) ,
819
+ logger,
820
+ } as IHttpConnectionOptions ;
821
+
822
+ const connection = new HttpConnection ( "http://tempuri.org" , options ) ;
823
+ connection . onreceive = ( ) => null ;
824
+ try {
825
+ await connection . start ( TransferFormat . Text ) ;
826
+ } finally {
827
+ await connection . stop ( ) ;
828
+ }
829
+
830
+ expect ( handlersSet ) . toBe ( true ) ;
831
+ } ) ;
832
+ } ) ;
833
+
834
+ it ( "transport handlers set before start for custom transports" , async ( ) => {
835
+ await VerifyLogger . run ( async ( logger ) => {
836
+ const availableTransport = { transport : "Custom" , transferFormats : [ "Text" ] } ;
837
+ let handlersSet = false ;
838
+ const transport : ITransport = {
839
+ connect : ( url : string , transferFormat : TransferFormat ) => {
840
+ if ( transport . onreceive && transport . onclose ) {
841
+ handlersSet = true ;
842
+ }
843
+ return Promise . resolve ( ) ;
844
+ } ,
845
+ onclose : null ,
846
+ onreceive : null ,
847
+ send : ( data : any ) => Promise . resolve ( ) ,
848
+ stop : ( ) => {
849
+ if ( transport . onclose ) {
850
+ transport . onclose ( ) ;
851
+ }
852
+ return Promise . resolve ( ) ;
853
+ } ,
854
+ } ;
855
+
856
+ const options : IHttpConnectionOptions = {
857
+ ...commonOptions ,
858
+ httpClient : new TestHttpClient ( )
859
+ . on ( "POST" , ( ) => ( { connectionId : "42" , availableTransports : [ availableTransport ] } ) ) ,
860
+ logger,
861
+ transport,
862
+ } as IHttpConnectionOptions ;
863
+
864
+ const connection = new HttpConnection ( "http://tempuri.org" , options ) ;
865
+ connection . onreceive = ( ) => null ;
866
+ try {
867
+ await connection . start ( TransferFormat . Text ) ;
868
+ } finally {
869
+ await connection . stop ( ) ;
870
+ }
871
+
872
+ expect ( handlersSet ) . toBe ( true ) ;
873
+ } ) ;
874
+ } ) ;
875
+
798
876
describe ( ".constructor" , ( ) => {
799
877
it ( "throws if no Url is provided" , async ( ) => {
800
878
// Force TypeScript to let us call the constructor incorrectly :)
0 commit comments