@@ -413,25 +413,27 @@ describe("hubConnection", () => {
413
413
} ) ;
414
414
} ) ;
415
415
416
- it ( "closed with error or start fails if hub cannot be created" , async ( done ) => {
416
+ it ( "closed with error or start fails if hub cannot be created" , async ( ) => {
417
417
const hubConnection = getConnectionBuilder ( transportType , ENDPOINT_BASE_URL + "/uncreatable" )
418
418
. withHubProtocol ( protocol )
419
419
. build ( ) ;
420
420
421
421
const expectedErrorMessage = "Server returned an error on close: Connection closed with an error. InvalidOperationException: Unable to resolve service for type 'System.Object' while attempting to activate 'FunctionalTests.UncreatableHub'." ;
422
422
423
+ const closePromise = new PromiseSource ( ) ;
423
424
// Either start will fail or onclose will be called. Never both.
424
425
hubConnection . onclose ( ( error ) => {
425
426
expect ( error ! . message ) . toEqual ( expectedErrorMessage ) ;
426
- done ( ) ;
427
+ closePromise . resolve ( ) ;
427
428
} ) ;
428
429
429
430
try {
430
431
await hubConnection . start ( ) ;
431
432
} catch ( error ) {
432
433
expect ( error ! . message ) . toEqual ( expectedErrorMessage ) ;
433
- done ( ) ;
434
+ closePromise . resolve ( ) ;
434
435
}
436
+ await closePromise ;
435
437
} ) ;
436
438
437
439
it ( "can handle different types" , ( done ) => {
@@ -565,7 +567,7 @@ describe("hubConnection", () => {
565
567
} ) ;
566
568
} ) ;
567
569
568
- it ( "can stream from client to server with rxjs" , async ( done ) => {
570
+ it ( "can stream from client to server with rxjs" , async ( ) => {
569
571
const hubConnection = getConnectionBuilder ( transportType )
570
572
. withHubProtocol ( protocol )
571
573
. build ( ) ;
@@ -579,10 +581,9 @@ describe("hubConnection", () => {
579
581
subject . complete ( ) ;
580
582
expect ( await resultPromise ) . toBe ( "Hello world!" ) ;
581
583
await hubConnection . stop ( ) ;
582
- done ( ) ;
583
584
} ) ;
584
585
585
- it ( "can stream from client to server and close with error with rxjs" , async ( done ) => {
586
+ it ( "can stream from client to server and close with error with rxjs" , async ( ) => {
586
587
const hubConnection = getConnectionBuilder ( transportType )
587
588
. withHubProtocol ( protocol )
588
589
. build ( ) ;
@@ -602,15 +603,14 @@ describe("hubConnection", () => {
602
603
} finally {
603
604
await hubConnection . stop ( ) ;
604
605
}
605
- done ( ) ;
606
606
} ) ;
607
607
} ) ;
608
608
} ) ;
609
609
610
610
eachTransport ( ( transportType ) => {
611
611
describe ( "over " + HttpTransportType [ transportType ] + " transport" , ( ) => {
612
612
613
- it ( "can connect to hub with authorization" , async ( done ) => {
613
+ it ( "can connect to hub with authorization" , async ( ) => {
614
614
const message = "你好,世界!" ;
615
615
616
616
try {
@@ -620,9 +620,10 @@ describe("hubConnection", () => {
620
620
accessTokenFactory : ( ) => jwtToken ,
621
621
} ) . build ( ) ;
622
622
623
+ const closePromise = new PromiseSource ( ) ;
623
624
hubConnection . onclose ( ( error ) => {
624
625
expect ( error ) . toBe ( undefined ) ;
625
- done ( ) ;
626
+ closePromise . resolve ( ) ;
626
627
} ) ;
627
628
await hubConnection . start ( ) ;
628
629
const response = await hubConnection . invoke ( "Echo" , message ) ;
@@ -631,24 +632,24 @@ describe("hubConnection", () => {
631
632
632
633
await hubConnection . stop ( ) ;
633
634
634
- done ( ) ;
635
+ await closePromise ;
635
636
} catch ( err ) {
636
637
fail ( err ) ;
637
- done ( ) ;
638
638
}
639
639
} ) ;
640
640
641
- it ( "can connect to hub with authorization using async token factory" , async ( done ) => {
641
+ it ( "can connect to hub with authorization using async token factory" , async ( ) => {
642
642
const message = "你好,世界!" ;
643
643
644
644
try {
645
645
const hubConnection = getConnectionBuilder ( transportType , ENDPOINT_BASE_URL + "/authorizedhub" , {
646
646
accessTokenFactory : ( ) => getJwtToken ( ENDPOINT_BASE_URL + "/generateJwtToken" ) ,
647
647
} ) . build ( ) ;
648
648
649
+ const closePromise = new PromiseSource ( ) ;
649
650
hubConnection . onclose ( ( error ) => {
650
651
expect ( error ) . toBe ( undefined ) ;
651
- done ( ) ;
652
+ closePromise . resolve ( ) ;
652
653
} ) ;
653
654
await hubConnection . start ( ) ;
654
655
const response = await hubConnection . invoke ( "Echo" , message ) ;
@@ -657,48 +658,49 @@ describe("hubConnection", () => {
657
658
658
659
await hubConnection . stop ( ) ;
659
660
660
- done ( ) ;
661
+ await closePromise ;
661
662
} catch ( err ) {
662
663
fail ( err ) ;
663
- done ( ) ;
664
664
}
665
665
} ) ;
666
666
667
667
if ( transportType !== HttpTransportType . LongPolling ) {
668
- it ( "terminates if no messages received within timeout interval" , async ( done ) => {
668
+ it ( "terminates if no messages received within timeout interval" , async ( ) => {
669
669
const hubConnection = getConnectionBuilder ( transportType ) . build ( ) ;
670
670
hubConnection . serverTimeoutInMilliseconds = 100 ;
671
671
672
+ const closePromise = new PromiseSource ( ) ;
672
673
hubConnection . onclose ( ( error ) => {
673
674
expect ( error ) . toEqual ( new Error ( "Server timeout elapsed without receiving a message from the server." ) ) ;
674
- done ( ) ;
675
+ closePromise . resolve ( ) ;
675
676
} ) ;
676
677
677
678
await hubConnection . start ( ) ;
679
+ await closePromise ;
678
680
} ) ;
679
681
}
680
682
681
- it ( "preserves cookies between requests" , async ( done ) => {
682
- const hubConnection = getConnectionBuilder ( transportType , HTTPORHTTPS_TESTHUBENDPOINT_URL ) . build ( ) ;
683
- await hubConnection . start ( ) ;
684
- const cookieValue = await hubConnection . invoke < string > ( "GetCookie" , "testCookie" ) ;
685
- const cookieValue2 = await hubConnection . invoke < string > ( "GetCookie" , "testCookie2" ) ;
686
- expect ( cookieValue ) . toEqual ( "testValue" ) ;
687
- expect ( cookieValue2 ) . toEqual ( "testValue2" ) ;
688
- await hubConnection . stop ( ) ;
689
- done ( ) ;
690
- } ) ;
683
+ if ( shouldRunHttpsTests ) {
684
+ it ( "preserves cookies between requests" , async ( ) => {
685
+ const hubConnection = getConnectionBuilder ( transportType , HTTPORHTTPS_TESTHUBENDPOINT_URL ) . build ( ) ;
686
+ await hubConnection . start ( ) ;
687
+ const cookieValue = await hubConnection . invoke < string > ( "GetCookie" , "testCookie" ) ;
688
+ const cookieValue2 = await hubConnection . invoke < string > ( "GetCookie" , "testCookie2" ) ;
689
+ expect ( cookieValue ) . toEqual ( "testValue" ) ;
690
+ expect ( cookieValue2 ) . toEqual ( "testValue2" ) ;
691
+ await hubConnection . stop ( ) ;
692
+ } ) ;
693
+ }
691
694
692
- it ( "expired cookies are not preserved" , async ( done ) => {
695
+ it ( "expired cookies are not preserved" , async ( ) => {
693
696
const hubConnection = getConnectionBuilder ( transportType , HTTPORHTTPS_TESTHUBENDPOINT_URL ) . build ( ) ;
694
697
await hubConnection . start ( ) ;
695
698
const cookieValue = await hubConnection . invoke < string > ( "GetCookie" , "expiredCookie" ) ;
696
699
expect ( cookieValue ) . toBeNull ( ) ;
697
700
await hubConnection . stop ( ) ;
698
- done ( ) ;
699
701
} ) ;
700
702
701
- it ( "can reconnect" , async ( done ) => {
703
+ it ( "can reconnect" , async ( ) => {
702
704
try {
703
705
const reconnectingPromise = new PromiseSource ( ) ;
704
706
const reconnectedPromise = new PromiseSource < string | undefined > ( ) ;
@@ -731,16 +733,13 @@ describe("hubConnection", () => {
731
733
expect ( response ) . toEqual ( "test" ) ;
732
734
733
735
await hubConnection . stop ( ) ;
734
-
735
- done ( ) ;
736
736
} catch ( err ) {
737
737
fail ( err ) ;
738
- done ( ) ;
739
738
}
740
739
} ) ;
741
740
} ) ;
742
741
743
- it ( "can change url in reconnecting state" , async ( done ) => {
742
+ it ( "can change url in reconnecting state" , async ( ) => {
744
743
try {
745
744
const reconnectingPromise = new PromiseSource ( ) ;
746
745
const hubConnection = getConnectionBuilder ( transportType )
@@ -762,16 +761,13 @@ describe("hubConnection", () => {
762
761
expect ( hubConnection . baseUrl ) . toBe ( "http://example123.com" ) ;
763
762
764
763
await hubConnection . stop ( ) ;
765
-
766
- done ( ) ;
767
764
} catch ( err ) {
768
765
fail ( err ) ;
769
- done ( ) ;
770
766
}
771
767
} ) ;
772
768
} ) ;
773
769
774
- it ( "can reconnect after negotiate redirect" , async ( done ) => {
770
+ it ( "can reconnect after negotiate redirect" , async ( ) => {
775
771
try {
776
772
const reconnectingPromise = new PromiseSource ( ) ;
777
773
const reconnectedPromise = new PromiseSource < string | undefined > ( ) ;
@@ -809,15 +805,12 @@ describe("hubConnection", () => {
809
805
expect ( postReconnectRedirects ) . toBeGreaterThan ( preReconnectRedirects ) ;
810
806
811
807
await hubConnection . stop ( ) ;
812
-
813
- done ( ) ;
814
808
} catch ( err ) {
815
809
fail ( err ) ;
816
- done ( ) ;
817
810
}
818
811
} ) ;
819
812
820
- it ( "can reconnect after skipping negotiation" , async ( done ) => {
813
+ it ( "can reconnect after skipping negotiation" , async ( ) => {
821
814
try {
822
815
const reconnectingPromise = new PromiseSource ( ) ;
823
816
const reconnectedPromise = new PromiseSource < string | undefined > ( ) ;
@@ -852,15 +845,12 @@ describe("hubConnection", () => {
852
845
expect ( response ) . toEqual ( "test" ) ;
853
846
854
847
await hubConnection . stop ( ) ;
855
-
856
- done ( ) ;
857
848
} catch ( err ) {
858
849
fail ( err ) ;
859
- done ( ) ;
860
850
}
861
851
} ) ;
862
852
863
- it ( "connection id matches server side connection id" , async ( done ) => {
853
+ it ( "connection id matches server side connection id" , async ( ) => {
864
854
try {
865
855
const reconnectingPromise = new PromiseSource ( ) ;
866
856
const reconnectedPromise = new PromiseSource < string | undefined > ( ) ;
@@ -899,15 +889,12 @@ describe("hubConnection", () => {
899
889
900
890
await hubConnection . stop ( ) ;
901
891
expect ( hubConnection . connectionId ) . toBeNull ( ) ;
902
-
903
- done ( ) ;
904
892
} catch ( err ) {
905
893
fail ( err ) ;
906
- done ( ) ;
907
894
}
908
895
} ) ;
909
896
910
- it ( "connection id is alwys null is negotiation is skipped" , async ( done ) => {
897
+ it ( "connection id is alwys null is negotiation is skipped" , async ( ) => {
911
898
try {
912
899
const hubConnection = getConnectionBuilder (
913
900
HttpTransportType . WebSockets ,
@@ -925,16 +912,13 @@ describe("hubConnection", () => {
925
912
await hubConnection . stop ( ) ;
926
913
927
914
expect ( hubConnection . connectionId ) . toBeNull ( ) ;
928
-
929
- done ( ) ;
930
915
} catch ( err ) {
931
916
fail ( err ) ;
932
- done ( ) ;
933
917
}
934
918
} ) ;
935
919
936
920
if ( typeof EventSource !== "undefined" ) {
937
- it ( "allows Server-Sent Events when negotiating for JSON protocol" , async ( done ) => {
921
+ it ( "allows Server-Sent Events when negotiating for JSON protocol" , async ( ) => {
938
922
const hubConnection = getConnectionBuilder ( undefined , TESTHUB_NOWEBSOCKETS_ENDPOINT_URL )
939
923
. withHubProtocol ( new JsonHubProtocol ( ) )
940
924
. build ( ) ;
@@ -946,14 +930,13 @@ describe("hubConnection", () => {
946
930
expect ( await hubConnection . invoke ( "GetActiveTransportName" ) ) . toEqual ( "ServerSentEvents" ) ;
947
931
948
932
await hubConnection . stop ( ) ;
949
- done ( ) ;
950
933
} catch ( e ) {
951
934
fail ( e ) ;
952
935
}
953
936
} ) ;
954
937
}
955
938
956
- it ( "skips Server-Sent Events when negotiating for MessagePack protocol" , async ( done ) => {
939
+ it ( "skips Server-Sent Events when negotiating for MessagePack protocol" , async ( ) => {
957
940
const hubConnection = getConnectionBuilder ( undefined , TESTHUB_NOWEBSOCKETS_ENDPOINT_URL )
958
941
. withHubProtocol ( new MessagePackHubProtocol ( ) )
959
942
. build ( ) ;
@@ -965,16 +948,14 @@ describe("hubConnection", () => {
965
948
expect ( await hubConnection . invoke ( "GetActiveTransportName" ) ) . toEqual ( "LongPolling" ) ;
966
949
967
950
await hubConnection . stop ( ) ;
968
- done ( ) ;
969
951
} catch ( e ) {
970
952
fail ( e ) ;
971
953
}
972
954
} ) ;
973
955
974
- it ( "transport falls back from WebSockets to SSE or LongPolling" , async ( done ) => {
956
+ it ( "transport falls back from WebSockets to SSE or LongPolling" , async ( ) => {
975
957
// Skip test on Node as there will always be a WebSockets implementation on Node
976
958
if ( typeof window === "undefined" ) {
977
- done ( ) ;
978
959
return ;
979
960
}
980
961
@@ -1000,11 +981,10 @@ describe("hubConnection", () => {
1000
981
fail ( e ) ;
1001
982
} finally {
1002
983
( window as any ) . WebSocket = oldWebSocket ;
1003
- done ( ) ;
1004
984
}
1005
985
} ) ;
1006
986
1007
- it ( "over LongPolling it sends DELETE request and waits for poll to terminate" , async ( done ) => {
987
+ it ( "over LongPolling it sends DELETE request and waits for poll to terminate" , async ( ) => {
1008
988
// Create an HTTP client to capture the poll
1009
989
const defaultClient = new DefaultHttpClient ( TestLogger . instance ) ;
1010
990
@@ -1052,14 +1032,12 @@ describe("hubConnection", () => {
1052
1032
} catch ( e ) {
1053
1033
fail ( e ) ;
1054
1034
} finally {
1055
- done ( ) ;
1056
1035
}
1057
1036
} ) ;
1058
1037
1059
- it ( "populates the Content-Type header when sending XMLHttpRequest" , async ( done ) => {
1038
+ it ( "populates the Content-Type header when sending XMLHttpRequest" , async ( ) => {
1060
1039
// Skip test on Node as this header isn't set (it was added for React-Native)
1061
1040
if ( typeof window === "undefined" ) {
1062
- done ( ) ;
1063
1041
return ;
1064
1042
}
1065
1043
const hubConnection = getConnectionBuilder ( HttpTransportType . LongPolling , TESTHUB_NOWEBSOCKETS_ENDPOINT_URL )
@@ -1075,7 +1053,6 @@ describe("hubConnection", () => {
1075
1053
expect ( await hubConnection . invoke ( "GetContentTypeHeader" ) ) . toEqual ( "text/plain;charset=UTF-8" ) ;
1076
1054
1077
1055
await hubConnection . stop ( ) ;
1078
- done ( ) ;
1079
1056
} catch ( e ) {
1080
1057
fail ( e ) ;
1081
1058
}
0 commit comments