1
1
// Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
- import { HubConnection , JsonHubProtocol , LogLevel , TransportType } from "@aspnet/signalr" ;
4
+ import { HubConnection , IHubConnectionOptions , JsonHubProtocol , LogLevel , TransportType } from "@aspnet/signalr" ;
5
5
import { MessagePackHubProtocol } from "@aspnet/signalr-protocol-msgpack" ;
6
6
7
7
import { eachTransport , eachTransportAndProtocol } from "./Common" ;
@@ -10,14 +10,19 @@ import { TestLogger } from "./TestLogger";
10
10
const TESTHUBENDPOINT_URL = "/testhub" ;
11
11
const TESTHUB_NOWEBSOCKETS_ENDPOINT_URL = "/testhub-nowebsockets" ;
12
12
13
+ const commonOptions : IHubConnectionOptions = {
14
+ logMessageContent : true ,
15
+ logger : TestLogger . instance ,
16
+ } ;
17
+
13
18
describe ( "hubConnection" , ( ) => {
14
19
eachTransportAndProtocol ( ( transportType , protocol ) => {
15
20
describe ( "using " + protocol . name + " over " + TransportType [ transportType ] + " transport" , ( ) => {
16
21
it ( "can invoke server method and receive result" , ( done ) => {
17
22
const message = "你好,世界!" ;
18
23
19
24
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
20
- logger : TestLogger . instance ,
25
+ ... commonOptions ,
21
26
protocol,
22
27
transport : transportType ,
23
28
} ) ;
@@ -44,7 +49,7 @@ describe("hubConnection", () => {
44
49
const message = "你好,世界!" ;
45
50
46
51
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
47
- logger : TestLogger . instance ,
52
+ ... commonOptions ,
48
53
protocol,
49
54
transport : transportType ,
50
55
} ) ;
@@ -67,7 +72,7 @@ describe("hubConnection", () => {
67
72
68
73
it ( "can invoke server method structural object and receive structural result" , ( done ) => {
69
74
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
70
- logger : TestLogger . instance ,
75
+ ... commonOptions ,
71
76
protocol,
72
77
transport : transportType ,
73
78
} ) ;
@@ -93,7 +98,7 @@ describe("hubConnection", () => {
93
98
94
99
it ( "can stream server method and receive result" , ( done ) => {
95
100
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
96
- logger : TestLogger . instance ,
101
+ ... commonOptions ,
97
102
protocol,
98
103
transport : transportType ,
99
104
} ) ;
@@ -127,7 +132,7 @@ describe("hubConnection", () => {
127
132
it ( "rethrows an exception from the server when invoking" , ( done ) => {
128
133
const errorMessage = "An unexpected error occurred invoking 'ThrowException' on the server. InvalidOperationException: An error occurred." ;
129
134
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
130
- logger : TestLogger . instance ,
135
+ ... commonOptions ,
131
136
protocol,
132
137
transport : transportType ,
133
138
} ) ;
@@ -151,7 +156,7 @@ describe("hubConnection", () => {
151
156
152
157
it ( "throws an exception when invoking streaming method with invoke" , ( done ) => {
153
158
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
154
- logger : TestLogger . instance ,
159
+ ... commonOptions ,
155
160
protocol,
156
161
transport : transportType ,
157
162
} ) ;
@@ -175,7 +180,7 @@ describe("hubConnection", () => {
175
180
176
181
it ( "throws an exception when receiving a streaming result for method called with invoke" , ( done ) => {
177
182
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
178
- logger : TestLogger . instance ,
183
+ ... commonOptions ,
179
184
protocol,
180
185
transport : transportType ,
181
186
} ) ;
@@ -200,7 +205,7 @@ describe("hubConnection", () => {
200
205
it ( "rethrows an exception from the server when streaming" , ( done ) => {
201
206
const errorMessage = "An unexpected error occurred invoking 'StreamThrowException' on the server. InvalidOperationException: An error occurred." ;
202
207
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
203
- logger : TestLogger . instance ,
208
+ ... commonOptions ,
204
209
protocol,
205
210
transport : transportType ,
206
211
} ) ;
@@ -229,7 +234,7 @@ describe("hubConnection", () => {
229
234
230
235
it ( "throws an exception when invoking hub method with stream" , ( done ) => {
231
236
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
232
- logger : TestLogger . instance ,
237
+ ... commonOptions ,
233
238
protocol,
234
239
transport : transportType ,
235
240
} ) ;
@@ -258,7 +263,7 @@ describe("hubConnection", () => {
258
263
259
264
it ( "can receive server calls" , ( done ) => {
260
265
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
261
- logger : TestLogger . instance ,
266
+ ... commonOptions ,
262
267
protocol,
263
268
transport : transportType ,
264
269
} ) ;
@@ -290,7 +295,7 @@ describe("hubConnection", () => {
290
295
291
296
it ( "can receive server calls without rebinding handler when restarted" , ( done ) => {
292
297
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
293
- logger : TestLogger . instance ,
298
+ ... commonOptions ,
294
299
protocol,
295
300
transport : transportType ,
296
301
} ) ;
@@ -347,7 +352,7 @@ describe("hubConnection", () => {
347
352
348
353
it ( "closed with error if hub cannot be created" , ( done ) => {
349
354
const hubConnection = new HubConnection ( "http://" + document . location . host + "/uncreatable" , {
350
- logger : TestLogger . instance ,
355
+ ... commonOptions ,
351
356
protocol,
352
357
transport : transportType ,
353
358
} ) ;
@@ -361,7 +366,7 @@ describe("hubConnection", () => {
361
366
362
367
it ( "can handle different types" , ( done ) => {
363
368
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
364
- logger : TestLogger . instance ,
369
+ ... commonOptions ,
365
370
protocol,
366
371
transport : transportType ,
367
372
} ) ;
@@ -409,7 +414,7 @@ describe("hubConnection", () => {
409
414
const message = "你好,世界!" ;
410
415
411
416
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
412
- logger : TestLogger . instance ,
417
+ ... commonOptions ,
413
418
protocol,
414
419
transport : transportType ,
415
420
} ) ;
@@ -464,7 +469,7 @@ describe("hubConnection", () => {
464
469
const jwtToken = await getJwtToken ( "http://" + document . location . host + "/generateJwtToken" ) ;
465
470
const hubConnection = new HubConnection ( "/authorizedhub" , {
466
471
accessTokenFactory : ( ) => jwtToken ,
467
- logger : TestLogger . instance ,
472
+ ... commonOptions ,
468
473
transport : transportType ,
469
474
} ) ;
470
475
hubConnection . onclose ( ( error ) => {
@@ -488,7 +493,7 @@ describe("hubConnection", () => {
488
493
if ( transportType !== TransportType . LongPolling ) {
489
494
it ( "terminates if no messages received within timeout interval" , ( done ) => {
490
495
const hubConnection = new HubConnection ( TESTHUBENDPOINT_URL , {
491
- logger : TestLogger . instance ,
496
+ ... commonOptions ,
492
497
timeoutInMilliseconds : 100 ,
493
498
transport : transportType ,
494
499
} ) ;
@@ -512,7 +517,7 @@ describe("hubConnection", () => {
512
517
if ( typeof EventSource !== "undefined" ) {
513
518
it ( "allows Server-Sent Events when negotiating for JSON protocol" , async ( done ) => {
514
519
const hubConnection = new HubConnection ( TESTHUB_NOWEBSOCKETS_ENDPOINT_URL , {
515
- logger : TestLogger . instance ,
520
+ ... commonOptions ,
516
521
protocol : new JsonHubProtocol ( ) ,
517
522
} ) ;
518
523
@@ -530,7 +535,7 @@ describe("hubConnection", () => {
530
535
531
536
it ( "skips Server-Sent Events when negotiating for MsgPack protocol" , async ( done ) => {
532
537
const hubConnection = new HubConnection ( TESTHUB_NOWEBSOCKETS_ENDPOINT_URL , {
533
- logger : TestLogger . instance ,
538
+ ... commonOptions ,
534
539
protocol : new MessagePackHubProtocol ( ) ,
535
540
} ) ;
536
541
0 commit comments