@@ -31,7 +31,7 @@ describe("HubConnection", () => {
31
31
const hubConnection = createHubConnection ( connection , logger ) ;
32
32
try {
33
33
await hubConnection . start ( ) ;
34
- expect ( connection . sentData . length ) . toBe ( 1 ) ;
34
+ expect ( connection . sentData . length ) . toBe ( 2 ) ;
35
35
expect ( JSON . parse ( connection . sentData [ 0 ] ) ) . toEqual ( {
36
36
protocol : "json" ,
37
37
version : 1 ,
@@ -448,7 +448,7 @@ describe("HubConnection", () => {
448
448
const subject = new Subject ( ) ;
449
449
const invokePromise = hubConnection . invoke ( "testMethod" , "arg" , subject ) ;
450
450
451
- expect ( JSON . parse ( connection . sentData [ 1 ] ) ) . toEqual ( {
451
+ expect ( JSON . parse ( connection . sentData [ 2 ] ) ) . toEqual ( {
452
452
arguments : [ "arg" ] ,
453
453
invocationId : "1" ,
454
454
streamIds : [ "0" ] ,
@@ -460,7 +460,7 @@ describe("HubConnection", () => {
460
460
await new Promise < void > ( ( resolve ) => {
461
461
setTimeout ( resolve , 50 ) ;
462
462
} ) ;
463
- expect ( JSON . parse ( connection . sentData [ 2 ] ) ) . toEqual ( {
463
+ expect ( JSON . parse ( connection . sentData [ 3 ] ) ) . toEqual ( {
464
464
invocationId : "0" ,
465
465
item : "item numero uno" ,
466
466
type : MessageType . StreamItem ,
@@ -485,7 +485,7 @@ describe("HubConnection", () => {
485
485
const subject = new Subject ( ) ;
486
486
await hubConnection . send ( "testMethod" , "arg" , subject ) ;
487
487
488
- expect ( JSON . parse ( connection . sentData [ 1 ] ) ) . toEqual ( {
488
+ expect ( JSON . parse ( connection . sentData [ 2 ] ) ) . toEqual ( {
489
489
arguments : [ "arg" ] ,
490
490
streamIds : [ "0" ] ,
491
491
target : "testMethod" ,
@@ -496,7 +496,7 @@ describe("HubConnection", () => {
496
496
await new Promise < void > ( ( resolve ) => {
497
497
setTimeout ( resolve , 50 ) ;
498
498
} ) ;
499
- expect ( JSON . parse ( connection . sentData [ 2 ] ) ) . toEqual ( {
499
+ expect ( JSON . parse ( connection . sentData [ 3 ] ) ) . toEqual ( {
500
500
invocationId : "0" ,
501
501
item : "item numero uno" ,
502
502
type : MessageType . StreamItem ,
@@ -528,7 +528,7 @@ describe("HubConnection", () => {
528
528
} ,
529
529
} ) ;
530
530
531
- expect ( JSON . parse ( connection . sentData [ 1 ] ) ) . toEqual ( {
531
+ expect ( JSON . parse ( connection . sentData [ 2 ] ) ) . toEqual ( {
532
532
arguments : [ "arg" ] ,
533
533
invocationId : "1" ,
534
534
streamIds : [ "0" ] ,
@@ -540,7 +540,7 @@ describe("HubConnection", () => {
540
540
await new Promise < void > ( ( resolve ) => {
541
541
setTimeout ( resolve , 50 ) ;
542
542
} ) ;
543
- expect ( JSON . parse ( connection . sentData [ 2 ] ) ) . toEqual ( {
543
+ expect ( JSON . parse ( connection . sentData [ 3 ] ) ) . toEqual ( {
544
544
invocationId : "0" ,
545
545
item : "item numero uno" ,
546
546
type : MessageType . StreamItem ,
@@ -1102,10 +1102,10 @@ describe("HubConnection", () => {
1102
1102
// async here to guarantee the sent message is written
1103
1103
await delayUntil ( 1 ) ;
1104
1104
1105
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1106
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1107
- expect ( connection . parsedSentData [ 1 ] . result ) . toEqual ( 10 ) ;
1108
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1105
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1106
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1107
+ expect ( connection . parsedSentData [ 2 ] . result ) . toEqual ( 10 ) ;
1108
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1109
1109
} finally {
1110
1110
await hubConnection . stop ( ) ;
1111
1111
}
@@ -1133,10 +1133,10 @@ describe("HubConnection", () => {
1133
1133
// async here to guarantee the sent message is written
1134
1134
await delayUntil ( 1 ) ;
1135
1135
1136
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1137
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1138
- expect ( connection . parsedSentData [ 1 ] . result ) . toBeNull ( ) ;
1139
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1136
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1137
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1138
+ expect ( connection . parsedSentData [ 2 ] . result ) . toBeNull ( ) ;
1139
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1140
1140
} finally {
1141
1141
await hubConnection . stop ( ) ;
1142
1142
}
@@ -1166,10 +1166,10 @@ describe("HubConnection", () => {
1166
1166
// async here to guarantee the sent message is written
1167
1167
await delayUntil ( 1 ) ;
1168
1168
1169
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1170
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1171
- expect ( connection . parsedSentData [ 1 ] . result ) . toEqual ( 13 ) ;
1172
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1169
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1170
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1171
+ expect ( connection . parsedSentData [ 2 ] . result ) . toEqual ( 13 ) ;
1172
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1173
1173
} finally {
1174
1174
await hubConnection . stop ( ) ;
1175
1175
}
@@ -1197,10 +1197,10 @@ describe("HubConnection", () => {
1197
1197
// async here to guarantee the sent message is written
1198
1198
await delayUntil ( 1 ) ;
1199
1199
1200
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1201
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1202
- expect ( connection . parsedSentData [ 1 ] . error ) . toEqual ( "Error: from callback" ) ;
1203
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1200
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1201
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1202
+ expect ( connection . parsedSentData [ 2 ] . error ) . toEqual ( "Error: from callback" ) ;
1203
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1204
1204
} finally {
1205
1205
await hubConnection . stop ( ) ;
1206
1206
}
@@ -1229,10 +1229,10 @@ describe("HubConnection", () => {
1229
1229
// async here to guarantee the sent message is written
1230
1230
await delayUntil ( 1 ) ;
1231
1231
1232
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1233
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1234
- expect ( connection . parsedSentData [ 1 ] . error ) . toEqual ( 'Client provided multiple results.' ) ;
1235
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1232
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1233
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1234
+ expect ( connection . parsedSentData [ 2 ] . error ) . toEqual ( 'Client provided multiple results.' ) ;
1235
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1236
1236
} finally {
1237
1237
await hubConnection . stop ( ) ;
1238
1238
}
@@ -1261,11 +1261,11 @@ describe("HubConnection", () => {
1261
1261
// async here to guarantee the sent message is written
1262
1262
await delayUntil ( 1 ) ;
1263
1263
1264
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1265
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1266
- expect ( connection . parsedSentData [ 1 ] . error ) . toEqual ( "Error: from callback" ) ;
1267
- expect ( connection . parsedSentData [ 1 ] . result ) . toBeUndefined ( ) ;
1268
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1264
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1265
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1266
+ expect ( connection . parsedSentData [ 2 ] . error ) . toEqual ( "Error: from callback" ) ;
1267
+ expect ( connection . parsedSentData [ 2 ] . result ) . toBeUndefined ( ) ;
1268
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1269
1269
} finally {
1270
1270
await hubConnection . stop ( ) ;
1271
1271
}
@@ -1294,11 +1294,11 @@ describe("HubConnection", () => {
1294
1294
// async here to guarantee the sent message is written
1295
1295
await delayUntil ( 1 ) ;
1296
1296
1297
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1298
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1299
- expect ( connection . parsedSentData [ 1 ] . result ) . toEqual ( 3 ) ;
1300
- expect ( connection . parsedSentData [ 1 ] . error ) . toBeUndefined ( ) ;
1301
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1297
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1298
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1299
+ expect ( connection . parsedSentData [ 2 ] . result ) . toEqual ( 3 ) ;
1300
+ expect ( connection . parsedSentData [ 2 ] . error ) . toBeUndefined ( ) ;
1301
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1302
1302
} finally {
1303
1303
await hubConnection . stop ( ) ;
1304
1304
}
@@ -1326,10 +1326,10 @@ describe("HubConnection", () => {
1326
1326
// async here to guarantee the sent message is written
1327
1327
await delayUntil ( 1 ) ;
1328
1328
1329
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1330
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1331
- expect ( connection . parsedSentData [ 1 ] . error ) . toEqual ( "Client didn't provide a result." ) ;
1332
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1329
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1330
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1331
+ expect ( connection . parsedSentData [ 2 ] . error ) . toEqual ( "Client didn't provide a result." ) ;
1332
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1333
1333
} finally {
1334
1334
await hubConnection . stop ( ) ;
1335
1335
}
@@ -1355,10 +1355,10 @@ describe("HubConnection", () => {
1355
1355
// async here to guarantee the sent message is written
1356
1356
await delayUntil ( 1 ) ;
1357
1357
1358
- expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1359
- expect ( connection . parsedSentData [ 1 ] . type ) . toEqual ( 3 ) ;
1360
- expect ( connection . parsedSentData [ 1 ] . error ) . toEqual ( "Client didn't provide a result." ) ;
1361
- expect ( connection . parsedSentData [ 1 ] . invocationId ) . toEqual ( "1" ) ;
1358
+ expect ( connection . parsedSentData . length ) . toEqual ( 3 ) ;
1359
+ expect ( connection . parsedSentData [ 2 ] . type ) . toEqual ( 3 ) ;
1360
+ expect ( connection . parsedSentData [ 2 ] . error ) . toEqual ( "Client didn't provide a result." ) ;
1361
+ expect ( connection . parsedSentData [ 2 ] . invocationId ) . toEqual ( "1" ) ;
1362
1362
} finally {
1363
1363
await hubConnection . stop ( ) ;
1364
1364
}
@@ -1386,7 +1386,7 @@ describe("HubConnection", () => {
1386
1386
// async here to guarantee the sent message is written
1387
1387
await delayUntil ( 1 ) ;
1388
1388
1389
- expect ( connection . parsedSentData . length ) . toEqual ( 1 ) ;
1389
+ expect ( connection . parsedSentData . length ) . toEqual ( 2 ) ;
1390
1390
} finally {
1391
1391
await hubConnection . stop ( ) ;
1392
1392
}
@@ -1405,9 +1405,9 @@ describe("HubConnection", () => {
1405
1405
1406
1406
hubConnection . stream ( "testStream" , "arg" , 42 ) ;
1407
1407
1408
- // Verify the message is sent (+ handshake)
1409
- expect ( connection . sentData . length ) . toBe ( 2 ) ;
1410
- expect ( JSON . parse ( connection . sentData [ 1 ] ) ) . toEqual ( {
1408
+ // Verify the message is sent (+ handshake + ping )
1409
+ expect ( connection . sentData . length ) . toBe ( 3 ) ;
1410
+ expect ( JSON . parse ( connection . sentData [ 2 ] ) ) . toEqual ( {
1411
1411
arguments : [
1412
1412
"arg" ,
1413
1413
42 ,
@@ -1416,9 +1416,6 @@ describe("HubConnection", () => {
1416
1416
target : "testStream" ,
1417
1417
type : MessageType . StreamInvocation ,
1418
1418
} ) ;
1419
-
1420
- // Close the connection
1421
- await hubConnection . stop ( ) ;
1422
1419
} finally {
1423
1420
await hubConnection . stop ( ) ;
1424
1421
}
@@ -1592,10 +1589,10 @@ describe("HubConnection", () => {
1592
1589
expect ( observer . itemsReceived ) . toEqual ( [ 1 ] ) ;
1593
1590
1594
1591
// Close message sent asynchronously so we need to wait
1595
- await delayUntil ( 1000 , ( ) => connection . sentData . length === 3 ) ;
1592
+ await delayUntil ( 1000 , ( ) => connection . sentData . length === 4 ) ;
1596
1593
// Verify the cancel is sent (+ handshake)
1597
- expect ( connection . sentData . length ) . toBe ( 3 ) ;
1598
- expect ( JSON . parse ( connection . sentData [ 2 ] ) ) . toEqual ( {
1594
+ expect ( connection . sentData . length ) . toBe ( 4 ) ;
1595
+ expect ( JSON . parse ( connection . sentData [ 3 ] ) ) . toEqual ( {
1599
1596
invocationId : connection . lastInvocationId ,
1600
1597
type : MessageType . CancelInvocation ,
1601
1598
} ) ;
@@ -1830,7 +1827,9 @@ class TestProtocol implements IHubProtocol {
1830
1827
}
1831
1828
1832
1829
public writeMessage ( message : HubMessage ) : any {
1833
-
1830
+ if ( message . type === 6 ) {
1831
+ return "{\"type\": 6}" + TextMessageFormat . RecordSeparator ;
1832
+ }
1834
1833
}
1835
1834
}
1836
1835
0 commit comments