@@ -105,6 +105,10 @@ describe('WebSocket', () => {
105
105
} ) ;
106
106
}
107
107
) ;
108
+
109
+ wss . on ( 'connection' , ( ws ) => {
110
+ ws . close ( ) ;
111
+ } ) ;
108
112
} ) ;
109
113
110
114
it ( 'throws an error when using an invalid `protocolVersion`' , ( ) => {
@@ -230,6 +234,10 @@ describe('WebSocket', () => {
230
234
wss . close ( done ) ;
231
235
} ;
232
236
} ) ;
237
+
238
+ wss . on ( 'connection' , ( ws ) => {
239
+ ws . close ( ) ;
240
+ } ) ;
233
241
} ) ;
234
242
235
243
it ( 'takes into account the data in the sender queue' , ( done ) => {
@@ -258,6 +266,10 @@ describe('WebSocket', () => {
258
266
} ) ;
259
267
}
260
268
) ;
269
+
270
+ wss . on ( 'connection' , ( ws ) => {
271
+ ws . close ( ) ;
272
+ } ) ;
261
273
} ) ;
262
274
263
275
it ( 'takes into account the data in the socket queue' , ( done ) => {
@@ -526,6 +538,10 @@ describe('WebSocket', () => {
526
538
wss . close ( done ) ;
527
539
} ) ;
528
540
} ) ;
541
+
542
+ wss . on ( 'connection' , ( ws ) => {
543
+ ws . close ( ) ;
544
+ } ) ;
529
545
} ) ;
530
546
531
547
it ( "emits a 'ping' event" , ( done ) => {
@@ -534,7 +550,10 @@ describe('WebSocket', () => {
534
550
ws . on ( 'ping' , ( ) => wss . close ( done ) ) ;
535
551
} ) ;
536
552
537
- wss . on ( 'connection' , ( ws ) => ws . ping ( ) ) ;
553
+ wss . on ( 'connection' , ( ws ) => {
554
+ ws . ping ( ) ;
555
+ ws . close ( ) ;
556
+ } ) ;
538
557
} ) ;
539
558
540
559
it ( "emits a 'pong' event" , ( done ) => {
@@ -543,7 +562,10 @@ describe('WebSocket', () => {
543
562
ws . on ( 'pong' , ( ) => wss . close ( done ) ) ;
544
563
} ) ;
545
564
546
- wss . on ( 'connection' , ( ws ) => ws . pong ( ) ) ;
565
+ wss . on ( 'connection' , ( ws ) => {
566
+ ws . pong ( ) ;
567
+ ws . close ( ) ;
568
+ } ) ;
547
569
} ) ;
548
570
} ) ;
549
571
@@ -977,7 +999,13 @@ describe('WebSocket', () => {
977
999
const port = wss . address ( ) . port ;
978
1000
const ws = new WebSocket ( `ws://localhost:${ port } /?token=qwerty` ) ;
979
1001
980
- ws . on ( 'open' , ( ) => wss . close ( done ) ) ;
1002
+ ws . on ( 'open' , ( ) => {
1003
+ wss . close ( done ) ;
1004
+ } ) ;
1005
+ } ) ;
1006
+
1007
+ wss . on ( 'connection' , ( ws ) => {
1008
+ ws . close ( ) ;
981
1009
} ) ;
982
1010
} ) ;
983
1011
@@ -986,7 +1014,13 @@ describe('WebSocket', () => {
986
1014
const port = wss . address ( ) . port ;
987
1015
const ws = new WebSocket ( `ws://localhost:${ port } ?token=qwerty` ) ;
988
1016
989
- ws . on ( 'open' , ( ) => wss . close ( done ) ) ;
1017
+ ws . on ( 'open' , ( ) => {
1018
+ wss . close ( done ) ;
1019
+ } ) ;
1020
+ } ) ;
1021
+
1022
+ wss . on ( 'connection' , ( ws ) => {
1023
+ ws . close ( ) ;
990
1024
} ) ;
991
1025
} ) ;
992
1026
} ) ;
@@ -1084,7 +1118,10 @@ describe('WebSocket', () => {
1084
1118
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1085
1119
1086
1120
ws . on ( 'open' , ( ) => {
1087
- ws . ping ( ( ) => ws . ping ( ) ) ;
1121
+ ws . ping ( ( ) => {
1122
+ ws . ping ( ) ;
1123
+ ws . close ( ) ;
1124
+ } ) ;
1088
1125
} ) ;
1089
1126
} ) ;
1090
1127
@@ -1103,7 +1140,10 @@ describe('WebSocket', () => {
1103
1140
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1104
1141
1105
1142
ws . on ( 'open' , ( ) => {
1106
- ws . ping ( 'hi' , ( ) => ws . ping ( 'hi' , true ) ) ;
1143
+ ws . ping ( 'hi' , ( ) => {
1144
+ ws . ping ( 'hi' , true ) ;
1145
+ ws . close ( ) ;
1146
+ } ) ;
1107
1147
} ) ;
1108
1148
} ) ;
1109
1149
@@ -1120,7 +1160,10 @@ describe('WebSocket', () => {
1120
1160
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1121
1161
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1122
1162
1123
- ws . on ( 'open' , ( ) => ws . ping ( 0 ) ) ;
1163
+ ws . on ( 'open' , ( ) => {
1164
+ ws . ping ( 0 ) ;
1165
+ ws . close ( ) ;
1166
+ } ) ;
1124
1167
} ) ;
1125
1168
1126
1169
wss . on ( 'connection' , ( ws ) => {
@@ -1144,6 +1187,10 @@ describe('WebSocket', () => {
1144
1187
wss . close ( done ) ;
1145
1188
} ) ;
1146
1189
} ) ;
1190
+
1191
+ wss . on ( 'connection' , ( ws ) => {
1192
+ ws . close ( ) ;
1193
+ } ) ;
1147
1194
} ) ;
1148
1195
} ) ;
1149
1196
@@ -1240,7 +1287,10 @@ describe('WebSocket', () => {
1240
1287
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1241
1288
1242
1289
ws . on ( 'open' , ( ) => {
1243
- ws . pong ( ( ) => ws . pong ( ) ) ;
1290
+ ws . pong ( ( ) => {
1291
+ ws . pong ( ) ;
1292
+ ws . close ( ) ;
1293
+ } ) ;
1244
1294
} ) ;
1245
1295
} ) ;
1246
1296
@@ -1259,7 +1309,10 @@ describe('WebSocket', () => {
1259
1309
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1260
1310
1261
1311
ws . on ( 'open' , ( ) => {
1262
- ws . pong ( 'hi' , ( ) => ws . pong ( 'hi' , true ) ) ;
1312
+ ws . pong ( 'hi' , ( ) => {
1313
+ ws . pong ( 'hi' , true ) ;
1314
+ ws . close ( ) ;
1315
+ } ) ;
1263
1316
} ) ;
1264
1317
} ) ;
1265
1318
@@ -1276,7 +1329,10 @@ describe('WebSocket', () => {
1276
1329
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1277
1330
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1278
1331
1279
- ws . on ( 'open' , ( ) => ws . pong ( 0 ) ) ;
1332
+ ws . on ( 'open' , ( ) => {
1333
+ ws . pong ( 0 ) ;
1334
+ ws . close ( ) ;
1335
+ } ) ;
1280
1336
} ) ;
1281
1337
1282
1338
wss . on ( 'connection' , ( ws ) => {
@@ -1300,6 +1356,10 @@ describe('WebSocket', () => {
1300
1356
wss . close ( done ) ;
1301
1357
} ) ;
1302
1358
} ) ;
1359
+
1360
+ wss . on ( 'connection' , ( ws ) => {
1361
+ ws . close ( ) ;
1362
+ } ) ;
1303
1363
} ) ;
1304
1364
} ) ;
1305
1365
@@ -1413,6 +1473,7 @@ describe('WebSocket', () => {
1413
1473
ws . on ( 'message' , ( msg , isBinary ) => {
1414
1474
assert . ok ( isBinary ) ;
1415
1475
ws . send ( msg ) ;
1476
+ ws . close ( ) ;
1416
1477
} ) ;
1417
1478
} ) ;
1418
1479
} ) ;
@@ -1432,6 +1493,7 @@ describe('WebSocket', () => {
1432
1493
wss . on ( 'connection' , ( ws ) => {
1433
1494
ws . on ( 'message' , ( msg , isBinary ) => {
1434
1495
ws . send ( msg , { binary : isBinary } ) ;
1496
+ ws . close ( ) ;
1435
1497
} ) ;
1436
1498
} ) ;
1437
1499
} ) ;
@@ -1443,6 +1505,7 @@ describe('WebSocket', () => {
1443
1505
ws . on ( 'open' , ( ) => {
1444
1506
ws . send ( 'fragment' , { fin : false } ) ;
1445
1507
ws . send ( 'fragment' , { fin : true } ) ;
1508
+ ws . close ( ) ;
1446
1509
} ) ;
1447
1510
} ) ;
1448
1511
@@ -1459,7 +1522,10 @@ describe('WebSocket', () => {
1459
1522
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1460
1523
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1461
1524
1462
- ws . on ( 'open' , ( ) => ws . send ( 0 ) ) ;
1525
+ ws . on ( 'open' , ( ) => {
1526
+ ws . send ( 0 ) ;
1527
+ ws . close ( ) ;
1528
+ } ) ;
1463
1529
} ) ;
1464
1530
1465
1531
wss . on ( 'connection' , ( ws ) => {
@@ -1488,7 +1554,11 @@ describe('WebSocket', () => {
1488
1554
1489
1555
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1490
1556
1491
- ws . on ( 'open' , ( ) => ws . send ( partial ) ) ;
1557
+ ws . on ( 'open' , ( ) => {
1558
+ ws . send ( partial ) ;
1559
+ ws . close ( ) ;
1560
+ } ) ;
1561
+
1492
1562
ws . on ( 'message' , ( message , isBinary ) => {
1493
1563
assert . deepStrictEqual ( message , buf ) ;
1494
1564
assert . ok ( isBinary ) ;
@@ -1514,7 +1584,11 @@ describe('WebSocket', () => {
1514
1584
1515
1585
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1516
1586
1517
- ws . on ( 'open' , ( ) => ws . send ( array . buffer ) ) ;
1587
+ ws . on ( 'open' , ( ) => {
1588
+ ws . send ( array . buffer ) ;
1589
+ ws . close ( ) ;
1590
+ } ) ;
1591
+
1518
1592
ws . onmessage = ( event ) => {
1519
1593
assert . ok ( event . data . equals ( Buffer . from ( array . buffer ) ) ) ;
1520
1594
wss . close ( done ) ;
@@ -1534,7 +1608,10 @@ describe('WebSocket', () => {
1534
1608
const buf = Buffer . from ( 'foobar' ) ;
1535
1609
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1536
1610
1537
- ws . on ( 'open' , ( ) => ws . send ( buf ) ) ;
1611
+ ws . on ( 'open' , ( ) => {
1612
+ ws . send ( buf ) ;
1613
+ ws . close ( ) ;
1614
+ } ) ;
1538
1615
1539
1616
ws . onmessage = ( event ) => {
1540
1617
assert . deepStrictEqual ( event . data , buf ) ;
@@ -1561,13 +1638,20 @@ describe('WebSocket', () => {
1561
1638
} ) ;
1562
1639
} ) ;
1563
1640
} ) ;
1641
+
1642
+ wss . on ( 'connection' , ( ws ) => {
1643
+ ws . close ( ) ;
1644
+ } ) ;
1564
1645
} ) ;
1565
1646
1566
1647
it ( 'works when the `data` argument is falsy' , ( done ) => {
1567
1648
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1568
1649
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1569
1650
1570
- ws . on ( 'open' , ( ) => ws . send ( ) ) ;
1651
+ ws . on ( 'open' , ( ) => {
1652
+ ws . send ( ) ;
1653
+ ws . close ( ) ;
1654
+ } ) ;
1571
1655
} ) ;
1572
1656
1573
1657
wss . on ( 'connection' , ( ws ) => {
@@ -1743,51 +1827,6 @@ describe('WebSocket', () => {
1743
1827
} ) ;
1744
1828
} ) ;
1745
1829
1746
- it ( 'throws an error if the first argument is invalid (1/2)' , ( done ) => {
1747
- const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1748
- const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1749
-
1750
- ws . on ( 'open' , ( ) => {
1751
- assert . throws (
1752
- ( ) => ws . close ( 'error' ) ,
1753
- / ^ T y p e E r r o r : F i r s t a r g u m e n t m u s t b e a v a l i d e r r o r c o d e n u m b e r $ /
1754
- ) ;
1755
-
1756
- wss . close ( done ) ;
1757
- } ) ;
1758
- } ) ;
1759
- } ) ;
1760
-
1761
- it ( 'throws an error if the first argument is invalid (2/2)' , ( done ) => {
1762
- const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1763
- const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1764
-
1765
- ws . on ( 'open' , ( ) => {
1766
- assert . throws (
1767
- ( ) => ws . close ( 1004 ) ,
1768
- / ^ T y p e E r r o r : F i r s t a r g u m e n t m u s t b e a v a l i d e r r o r c o d e n u m b e r $ /
1769
- ) ;
1770
-
1771
- wss . close ( done ) ;
1772
- } ) ;
1773
- } ) ;
1774
- } ) ;
1775
-
1776
- it ( 'throws an error if the message is greater than 123 bytes' , ( done ) => {
1777
- const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1778
- const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
1779
-
1780
- ws . on ( 'open' , ( ) => {
1781
- assert . throws (
1782
- ( ) => ws . close ( 1000 , 'a' . repeat ( 124 ) ) ,
1783
- / ^ R a n g e E r r o r : T h e m e s s a g e m u s t n o t b e g r e a t e r t h a n 1 2 3 b y t e s $ /
1784
- ) ;
1785
-
1786
- wss . close ( done ) ;
1787
- } ) ;
1788
- } ) ;
1789
- } ) ;
1790
-
1791
1830
it ( 'sends the close status code only when necessary' , ( done ) => {
1792
1831
let sent ;
1793
1832
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
@@ -2206,7 +2245,11 @@ describe('WebSocket', () => {
2206
2245
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
2207
2246
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
2208
2247
2209
- ws . addEventListener ( 'open' , ( ) => ws . send ( 'hi' ) ) ;
2248
+ ws . addEventListener ( 'open' , ( ) => {
2249
+ ws . send ( 'hi' ) ;
2250
+ ws . close ( ) ;
2251
+ } ) ;
2252
+
2210
2253
ws . addEventListener ( 'message' , ( messageEvent ) => {
2211
2254
assert . strictEqual ( messageEvent . data , 'hi' ) ;
2212
2255
wss . close ( done ) ;
@@ -2262,7 +2305,7 @@ describe('WebSocket', () => {
2262
2305
ws . addEventListener ( 'message' , ( messageEvent ) => {
2263
2306
assert . strictEqual ( messageEvent . type , 'message' ) ;
2264
2307
assert . strictEqual ( messageEvent . target , ws ) ;
2265
- wss . close ( ) ;
2308
+ ws . close ( ) ;
2266
2309
} ) ;
2267
2310
ws . addEventListener ( 'close' , ( closeEvent ) => {
2268
2311
assert . strictEqual ( closeEvent . type , 'close' ) ;
@@ -2275,7 +2318,7 @@ describe('WebSocket', () => {
2275
2318
assert . strictEqual ( errorEvent . target , ws ) ;
2276
2319
assert . strictEqual ( errorEvent . error , err ) ;
2277
2320
2278
- done ( ) ;
2321
+ wss . close ( done ) ;
2279
2322
} ) ;
2280
2323
} ) ;
2281
2324
@@ -2292,7 +2335,10 @@ describe('WebSocket', () => {
2292
2335
} ;
2293
2336
} ) ;
2294
2337
2295
- wss . on ( 'connection' , ( ws ) => ws . send ( new Uint8Array ( 4096 ) ) ) ;
2338
+ wss . on ( 'connection' , ( ws ) => {
2339
+ ws . send ( new Uint8Array ( 4096 ) ) ;
2340
+ ws . close ( ) ;
2341
+ } ) ;
2296
2342
} ) ;
2297
2343
2298
2344
it ( 'ignores `binaryType` for text messages' , ( done ) => {
@@ -2307,7 +2353,10 @@ describe('WebSocket', () => {
2307
2353
} ;
2308
2354
} ) ;
2309
2355
2310
- wss . on ( 'connection' , ( ws ) => ws . send ( 'foo' ) ) ;
2356
+ wss . on ( 'connection' , ( ws ) => {
2357
+ ws . send ( 'foo' ) ;
2358
+ ws . close ( ) ;
2359
+ } ) ;
2311
2360
} ) ;
2312
2361
2313
2362
it ( 'allows to update `binaryType` on the fly' , ( done ) => {
@@ -2337,7 +2386,10 @@ describe('WebSocket', () => {
2337
2386
ws . onopen = ( ) => {
2338
2387
testType ( 'nodebuffer' , ( ) => {
2339
2388
testType ( 'arraybuffer' , ( ) => {
2340
- testType ( 'fragments' , ( ) => wss . close ( done ) ) ;
2389
+ testType ( 'fragments' , ( ) => {
2390
+ ws . close ( ) ;
2391
+ wss . close ( done ) ;
2392
+ } ) ;
2341
2393
} ) ;
2342
2394
} ) ;
2343
2395
} ;
@@ -2361,14 +2413,15 @@ describe('WebSocket', () => {
2361
2413
const wss = new WebSocket . Server ( { server } ) ;
2362
2414
2363
2415
wss . on ( 'connection' , ( ) => {
2364
- wss . close ( ) ;
2365
2416
server . close ( done ) ;
2366
2417
} ) ;
2367
2418
2368
2419
server . listen ( 0 , ( ) => {
2369
2420
const ws = new WebSocket ( `wss://127.0.0.1:${ server . address ( ) . port } ` , {
2370
2421
rejectUnauthorized : false
2371
2422
} ) ;
2423
+
2424
+ ws . on ( 'open' , ws . close ) ;
2372
2425
} ) ;
2373
2426
} ) ;
2374
2427
@@ -2392,7 +2445,6 @@ describe('WebSocket', () => {
2392
2445
wss . on ( 'connection' , ( ) => {
2393
2446
assert . ok ( success ) ;
2394
2447
server . close ( done ) ;
2395
- wss . close ( ) ;
2396
2448
} ) ;
2397
2449
2398
2450
server . listen ( 0 , ( ) => {
@@ -2401,6 +2453,8 @@ describe('WebSocket', () => {
2401
2453
key : fs . readFileSync ( 'test/fixtures/client-key.pem' ) ,
2402
2454
rejectUnauthorized : false
2403
2455
} ) ;
2456
+
2457
+ ws . on ( 'open' , ws . close ) ;
2404
2458
} ) ;
2405
2459
} ) ;
2406
2460
@@ -2435,7 +2489,6 @@ describe('WebSocket', () => {
2435
2489
assert . deepStrictEqual ( message , Buffer . from ( 'foobar' ) ) ;
2436
2490
assert . ok ( ! isBinary ) ;
2437
2491
server . close ( done ) ;
2438
- wss . close ( ) ;
2439
2492
} ) ;
2440
2493
} ) ;
2441
2494
@@ -2444,7 +2497,10 @@ describe('WebSocket', () => {
2444
2497
rejectUnauthorized : false
2445
2498
} ) ;
2446
2499
2447
- ws . on ( 'open' , ( ) => ws . send ( 'foobar' ) ) ;
2500
+ ws . on ( 'open' , ( ) => {
2501
+ ws . send ( 'foobar' ) ;
2502
+ ws . close ( ) ;
2503
+ } ) ;
2448
2504
} ) ;
2449
2505
} ) ;
2450
2506
@@ -2460,6 +2516,7 @@ describe('WebSocket', () => {
2460
2516
ws . on ( 'message' , ( message , isBinary ) => {
2461
2517
assert . ok ( isBinary ) ;
2462
2518
ws . send ( message ) ;
2519
+ ws . close ( ) ;
2463
2520
} ) ;
2464
2521
} ) ;
2465
2522
@@ -2474,7 +2531,6 @@ describe('WebSocket', () => {
2474
2531
assert . ok ( isBinary ) ;
2475
2532
2476
2533
server . close ( done ) ;
2477
- wss . close ( ) ;
2478
2534
} ) ;
2479
2535
} ) ;
2480
2536
} ) . timeout ( 4000 ) ;
@@ -2712,7 +2768,11 @@ describe('WebSocket', () => {
2712
2768
perMessageDeflate : { threshold : 0 }
2713
2769
} ) ;
2714
2770
2715
- ws . on ( 'open' , ( ) => ws . send ( 'hi' , { compress : true } ) ) ;
2771
+ ws . on ( 'open' , ( ) => {
2772
+ ws . send ( 'hi' , { compress : true } ) ;
2773
+ ws . close ( ) ;
2774
+ } ) ;
2775
+
2716
2776
ws . on ( 'message' , ( message , isBinary ) => {
2717
2777
assert . deepStrictEqual ( message , Buffer . from ( 'hi' ) ) ;
2718
2778
assert . ok ( ! isBinary ) ;
@@ -2745,7 +2805,11 @@ describe('WebSocket', () => {
2745
2805
perMessageDeflate : { threshold : 0 }
2746
2806
} ) ;
2747
2807
2748
- ws . on ( 'open' , ( ) => ws . send ( array , { compress : true } ) ) ;
2808
+ ws . on ( 'open' , ( ) => {
2809
+ ws . send ( array , { compress : true } ) ;
2810
+ ws . close ( ) ;
2811
+ } ) ;
2812
+
2749
2813
ws . on ( 'message' , ( message , isBinary ) => {
2750
2814
assert . deepStrictEqual ( message , Buffer . from ( array . buffer ) ) ;
2751
2815
assert . ok ( isBinary ) ;
@@ -2779,7 +2843,11 @@ describe('WebSocket', () => {
2779
2843
perMessageDeflate : { threshold : 0 }
2780
2844
} ) ;
2781
2845
2782
- ws . on ( 'open' , ( ) => ws . send ( array . buffer , { compress : true } ) ) ;
2846
+ ws . on ( 'open' , ( ) => {
2847
+ ws . send ( array . buffer , { compress : true } ) ;
2848
+ ws . close ( ) ;
2849
+ } ) ;
2850
+
2783
2851
ws . on ( 'message' , ( message , isBinary ) => {
2784
2852
assert . deepStrictEqual ( message , Buffer . from ( array . buffer ) ) ;
2785
2853
assert . ok ( isBinary ) ;
@@ -2918,7 +2986,11 @@ describe('WebSocket', () => {
2918
2986
perMessageDeflate : false
2919
2987
} ) ;
2920
2988
2921
- ws . on ( 'open' , ( ) => ws . send ( 'hi' , { compress : true } ) ) ;
2989
+ ws . on ( 'open' , ( ) => {
2990
+ ws . send ( 'hi' , { compress : true } ) ;
2991
+ ws . close ( ) ;
2992
+ } ) ;
2993
+
2922
2994
ws . on ( 'message' , ( message , isBinary ) => {
2923
2995
assert . deepStrictEqual ( message , Buffer . from ( 'hi' ) ) ;
2924
2996
assert . ok ( ! isBinary ) ;
@@ -2934,10 +3006,10 @@ describe('WebSocket', () => {
2934
3006
} ) ;
2935
3007
2936
3008
it ( 'calls the callback if the socket is closed prematurely' , ( done ) => {
3009
+ const called = [ ] ;
2937
3010
const wss = new WebSocket . Server (
2938
3011
{ perMessageDeflate : true , port : 0 } ,
2939
3012
( ) => {
2940
- const called = [ ] ;
2941
3013
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` , {
2942
3014
perMessageDeflate : { threshold : 0 }
2943
3015
} ) ;
@@ -2966,15 +3038,15 @@ describe('WebSocket', () => {
2966
3038
) ;
2967
3039
} ) ;
2968
3040
} ) ;
2969
-
2970
- ws . on ( 'close' , ( ) => {
2971
- assert . deepStrictEqual ( called , [ 1 , 2 ] ) ;
2972
- wss . close ( done ) ;
2973
- } ) ;
2974
3041
}
2975
3042
) ;
2976
3043
2977
3044
wss . on ( 'connection' , ( ws ) => {
3045
+ ws . on ( 'close' , ( ) => {
3046
+ assert . deepStrictEqual ( called , [ 1 , 2 ] ) ;
3047
+ wss . close ( done ) ;
3048
+ } ) ;
3049
+
2978
3050
ws . _socket . end ( ) ;
2979
3051
} ) ;
2980
3052
} ) ;
0 commit comments