File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -626,25 +626,27 @@ describe('WebSocket', () => {
626
626
} ) ;
627
627
} ) ;
628
628
629
- it ( 'does not re-emit `net.Socket` errors' , ( done ) => {
630
- const codes = [ 'EPIPE' , 'ECONNABORTED' , 'ECANCELED' , 'ECONNRESET' ] ;
629
+ it ( 'does not re-emit `net.Socket` errors' , function ( done ) {
630
+ //
631
+ // `socket.resetAndDestroy()` is not available in Node.js < 16.17.0.
632
+ //
633
+ if ( process . versions . modules < 93 ) return this . skip ( ) ;
634
+
631
635
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
632
636
const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
633
637
634
638
ws . on ( 'open' , ( ) => {
635
639
ws . _socket . on ( 'error' , ( err ) => {
636
640
assert . ok ( err instanceof Error ) ;
637
- assert . ok ( codes . includes ( err . code ) , `Unexpected code: ${ err . code } ` ) ;
641
+ assert . strictEqual ( err . code , 'ECONNRESET' ) ;
638
642
ws . on ( 'close' , ( code , message ) => {
639
643
assert . strictEqual ( code , 1006 ) ;
640
644
assert . strictEqual ( message , EMPTY_BUFFER ) ;
641
645
wss . close ( done ) ;
642
646
} ) ;
643
647
} ) ;
644
648
645
- for ( const client of wss . clients ) client . terminate ( ) ;
646
- ws . send ( 'foo' ) ;
647
- ws . send ( 'bar' ) ;
649
+ wss . clients . values ( ) . next ( ) . value . _socket . resetAndDestroy ( ) ;
648
650
} ) ;
649
651
} ) ;
650
652
} ) ;
You can’t perform that action at this time.
0 commit comments