@@ -25,42 +25,46 @@ async function initSocketIOConnection() {
2525 return socket ;
2626}
2727
28- // imported from https://github.com/socketio/socket.io/tree/main/docs/socket.io-protocol/v5-test-suite
29- describe ( "Socket.IO protocol" , ( ) => {
30- beforeAll ( ( ) => {
31- const io = new Server ( ) ;
28+ function setup ( ) {
29+ const io = new Server ( ) ;
3230
33- const engine = new Engine ( {
34- path : "/socket.io/" ,
35- pingInterval : PING_INTERVAL ,
36- pingTimeout : PING_TIMEOUT ,
37- } ) ;
31+ const engine = new Engine ( {
32+ path : "/socket.io/" ,
33+ pingInterval : PING_INTERVAL ,
34+ pingTimeout : PING_TIMEOUT ,
35+ } ) ;
3836
39- io . bind ( engine ) ;
37+ io . bind ( engine ) ;
4038
41- io . on ( "connection" , ( socket ) => {
42- socket . emit ( "auth" , socket . handshake . auth ) ;
39+ io . on ( "connection" , ( socket ) => {
40+ expect ( socket . handshake . headers ) . toContainKey ( "host" ) ;
4341
44- socket . on ( "message" , ( ...args ) => {
45- socket . emit . apply ( socket , [ "message-back" , ...args ] ) ;
46- } ) ;
42+ socket . emit ( "auth" , socket . handshake . auth ) ;
4743
48- socket . on ( "message-with-ack" , ( ...args ) => {
49- const ack = args . pop ( ) ;
50- ack ( ...args ) ;
51- } ) ;
44+ socket . on ( "message" , ( ...args ) => {
45+ socket . emit . apply ( socket , [ "message-back" , ...args ] ) ;
5246 } ) ;
5347
54- io . of ( "/custom" ) . on ( "connection" , ( socket ) => {
55- socket . emit ( "auth" , socket . handshake . auth ) ;
48+ socket . on ( "message-with-ack" , ( ...args ) => {
49+ const ack = args . pop ( ) ;
50+ ack ( ...args ) ;
5651 } ) ;
52+ } ) ;
5753
58- Bun . serve ( {
59- port : 3001 ,
60- ...engine . handler ( ) ,
61- } ) ;
54+ io . of ( "/custom" ) . on ( "connection" , ( socket ) => {
55+ socket . emit ( "auth" , socket . handshake . auth ) ;
6256 } ) ;
6357
58+ Bun . serve ( {
59+ port : 3001 ,
60+ ...engine . handler ( ) ,
61+ } ) ;
62+ }
63+
64+ // imported from https://github.com/socketio/socket.io/tree/main/docs/socket.io-protocol/v5-test-suite
65+ describe ( "Socket.IO protocol" , ( ) => {
66+ beforeAll ( ( ) => setup ( ) ) ;
67+
6468 describe ( "connect" , ( ) => {
6569 it ( "should allow connection to the main namespace" , async ( ) => {
6670 const socket = createWebSocket (
0 commit comments