@@ -9,25 +9,29 @@ import { ITransport, TransportType, TransferMode } from "../src/Transports"
9
9
import { eachTransport , eachEndpointUrl } from "./Common" ;
10
10
import { HttpResponse } from "../src/index" ;
11
11
12
+ const commonOptions : IHttpConnectionOptions = {
13
+ logger : null
14
+ } ;
15
+
12
16
describe ( "HttpConnection" , ( ) => {
13
17
it ( "cannot be created with relative url if document object is not present" , ( ) => {
14
- expect ( ( ) => new HttpConnection ( "/test" ) )
18
+ expect ( ( ) => new HttpConnection ( "/test" , commonOptions ) )
15
19
. toThrow ( new Error ( "Cannot resolve '/test'." ) ) ;
16
20
} ) ;
17
21
18
22
it ( "cannot be created with relative url if window object is not present" , ( ) => {
19
23
( < any > global ) . window = { } ;
20
- expect ( ( ) => new HttpConnection ( "/test" ) )
24
+ expect ( ( ) => new HttpConnection ( "/test" , commonOptions ) )
21
25
. toThrow ( new Error ( "Cannot resolve '/test'." ) ) ;
22
26
delete ( < any > global ) . window ;
23
27
} ) ;
24
28
25
29
it ( "starting connection fails if getting id fails" , async ( done ) => {
26
30
let options : IHttpConnectionOptions = {
31
+ ...commonOptions ,
27
32
httpClient : new TestHttpClient ( )
28
33
. on ( "POST" , r => Promise . reject ( "error" ) )
29
34
. on ( "GET" , r => "" ) ,
30
- logger : null
31
35
} as IHttpConnectionOptions ;
32
36
33
37
let connection = new HttpConnection ( "http://tempuri.org" , options ) ;
@@ -45,6 +49,7 @@ describe("HttpConnection", () => {
45
49
46
50
it ( "cannot start a running connection" , async ( done ) => {
47
51
let options : IHttpConnectionOptions = {
52
+ ...commonOptions ,
48
53
httpClient : new TestHttpClient ( )
49
54
. on ( "POST" , r => {
50
55
connection . start ( )
@@ -58,7 +63,6 @@ describe("HttpConnection", () => {
58
63
} ) ;
59
64
return Promise . reject ( "error" ) ;
60
65
} ) ,
61
- logger : null
62
66
} as IHttpConnectionOptions ;
63
67
64
68
let connection = new HttpConnection ( "http://tempuri.org" , options ) ;
@@ -75,13 +79,13 @@ describe("HttpConnection", () => {
75
79
it ( "can start a stopped connection" , async ( done ) => {
76
80
let negotiateCalls = 0 ;
77
81
let options : IHttpConnectionOptions = {
82
+ ...commonOptions ,
78
83
httpClient : new TestHttpClient ( )
79
84
. on ( "POST" , r => {
80
85
negotiateCalls += 1 ;
81
86
return Promise . reject ( "reached negotiate" ) ;
82
87
} )
83
88
. on ( "GET" , r => "" ) ,
84
- logger : null
85
89
} as IHttpConnectionOptions ;
86
90
87
91
let connection = new HttpConnection ( "http://tempuri.org" , options ) ;
@@ -103,6 +107,7 @@ describe("HttpConnection", () => {
103
107
104
108
it ( "can stop a starting connection" , async ( done ) => {
105
109
let options : IHttpConnectionOptions = {
110
+ ...commonOptions ,
106
111
httpClient : new TestHttpClient ( )
107
112
. on ( "POST" , r => {
108
113
connection . stop ( ) ;
@@ -112,7 +117,6 @@ describe("HttpConnection", () => {
112
117
connection . stop ( ) ;
113
118
return "" ;
114
119
} ) ,
115
- logger : null
116
120
} as IHttpConnectionOptions ;
117
121
118
122
let connection = new HttpConnection ( "http://tempuri.org" , options ) ;
@@ -128,7 +132,7 @@ describe("HttpConnection", () => {
128
132
} ) ;
129
133
130
134
it ( "can stop a non-started connection" , async ( done ) => {
131
- let connection = new HttpConnection ( "http://tempuri.org" ) ;
135
+ let connection = new HttpConnection ( "http://tempuri.org" , commonOptions ) ;
132
136
await connection . stop ( ) ;
133
137
done ( ) ;
134
138
} ) ;
@@ -151,11 +155,11 @@ describe("HttpConnection", () => {
151
155
}
152
156
153
157
let options : IHttpConnectionOptions = {
158
+ ...commonOptions ,
154
159
httpClient : new TestHttpClient ( )
155
160
. on ( "POST" , r => "{ \"connectionId\": \"42\" }" )
156
161
. on ( "GET" , r => "" ) ,
157
162
transport : fakeTransport ,
158
- logger : null ,
159
163
} as IHttpConnectionOptions ;
160
164
161
165
@@ -178,6 +182,7 @@ describe("HttpConnection", () => {
178
182
let negotiateUrl : string ;
179
183
let connection : HttpConnection ;
180
184
let options : IHttpConnectionOptions = {
185
+ ...commonOptions ,
181
186
httpClient : new TestHttpClient ( )
182
187
. on ( "POST" , r => {
183
188
negotiateUrl = r . url ;
@@ -188,7 +193,6 @@ describe("HttpConnection", () => {
188
193
connection . stop ( ) ;
189
194
return "" ;
190
195
} ) ,
191
- logger : null
192
196
} as IHttpConnectionOptions ;
193
197
194
198
connection = new HttpConnection ( givenUrl , options ) ;
@@ -212,11 +216,11 @@ describe("HttpConnection", () => {
212
216
}
213
217
it ( `cannot be started if requested ${ TransportType [ requestedTransport ] } transport not available on server` , async done => {
214
218
let options : IHttpConnectionOptions = {
219
+ ...commonOptions ,
215
220
httpClient : new TestHttpClient ( )
216
221
. on ( "POST" , r => "{ \"connectionId\": \"42\", \"availableTransports\": [] }" )
217
222
. on ( "GET" , r => "" ) ,
218
223
transport : requestedTransport ,
219
- logger : null
220
224
} as IHttpConnectionOptions ;
221
225
222
226
let connection = new HttpConnection ( "http://tempuri.org" , options ) ;
@@ -234,10 +238,10 @@ describe("HttpConnection", () => {
234
238
235
239
it ( "cannot be started if no transport available on server and no transport requested" , async done => {
236
240
let options : IHttpConnectionOptions = {
241
+ ...commonOptions ,
237
242
httpClient : new TestHttpClient ( )
238
243
. on ( "POST" , r => "{ \"connectionId\": \"42\", \"availableTransports\": [] }" )
239
244
. on ( "GET" , r => "" ) ,
240
- logger : null
241
245
} as IHttpConnectionOptions ;
242
246
243
247
let connection = new HttpConnection ( "http://tempuri.org" , options ) ;
@@ -254,9 +258,9 @@ describe("HttpConnection", () => {
254
258
255
259
it ( 'does not send negotiate request if WebSockets transport requested explicitly' , async done => {
256
260
let options : IHttpConnectionOptions = {
261
+ ...commonOptions ,
257
262
httpClient : new TestHttpClient ( ) ,
258
263
transport : TransportType . WebSockets ,
259
- logger : null
260
264
} as IHttpConnectionOptions ;
261
265
262
266
let connection = new HttpConnection ( "http://tempuri.org" , options ) ;
@@ -291,11 +295,11 @@ describe("HttpConnection", () => {
291
295
} as ITransport ;
292
296
293
297
let options : IHttpConnectionOptions = {
298
+ ...commonOptions ,
294
299
httpClient : new TestHttpClient ( )
295
300
. on ( "POST" , r => "{ \"connectionId\": \"42\", \"availableTransports\": [] }" )
296
301
. on ( "GET" , r => "" ) ,
297
302
transport : fakeTransport ,
298
- logger : null
299
303
} as IHttpConnectionOptions ;
300
304
301
305
let connection = new HttpConnection ( "https://tempuri.org" , options ) ;
0 commit comments