22
33const { tspl } = require ( '@matteo.collina/tspl' )
44const { describe, test, after } = require ( 'node:test' )
5- const assert = require ( 'node:assert' )
65const { WebSocketServer } = require ( 'ws' )
76const { WebSocket } = require ( '../..' )
87
98describe ( 'Close' , ( ) => {
10- test ( 'Close with code' , ( ) => {
9+ test ( 'Close with code' , ( t ) => {
1110 return new Promise ( ( resolve ) => {
1211 const server = new WebSocketServer ( { port : 0 } )
1312
1413 server . on ( 'connection' , ( ws ) => {
1514 ws . on ( 'close' , ( code ) => {
16- assert . equal ( code , 1000 )
15+ t . assert . strictEqual ( code , 1000 )
1716 server . close ( )
1817 resolve ( )
1918 } )
@@ -24,14 +23,14 @@ describe('Close', () => {
2423 } )
2524 } )
2625
27- test ( 'Close with code and reason' , ( ) => {
26+ test ( 'Close with code and reason' , ( t ) => {
2827 return new Promise ( ( resolve ) => {
2928 const server = new WebSocketServer ( { port : 0 } )
3029
3130 server . on ( 'connection' , ( ws ) => {
3231 ws . on ( 'close' , ( code , reason ) => {
33- assert . equal ( code , 1000 )
34- assert . deepStrictEqual ( reason , Buffer . from ( 'Goodbye' ) )
32+ t . assert . strictEqual ( code , 1000 )
33+ t . assert . deepStrictEqual ( reason , Buffer . from ( 'Goodbye' ) )
3534 server . close ( )
3635 resolve ( )
3736 } )
@@ -42,22 +41,22 @@ describe('Close', () => {
4241 } )
4342 } )
4443
45- test ( 'Close with invalid code' , ( ) => {
44+ test ( 'Close with invalid code' , ( t ) => {
4645 const server = new WebSocketServer ( { port : 0 } )
4746
4847 const ws = new WebSocket ( `ws://localhost:${ server . address ( ) . port } ` )
4948
5049 return new Promise ( ( resolve ) => {
5150 ws . addEventListener ( 'open' , ( ) => {
52- assert . throws (
51+ t . assert . throws (
5352 ( ) => ws . close ( 2999 ) ,
5453 {
5554 name : 'InvalidAccessError' ,
5655 constructor : DOMException
5756 }
5857 )
5958
60- assert . throws (
59+ t . assert . throws (
6160 ( ) => ws . close ( 5000 ) ,
6261 {
6362 name : 'InvalidAccessError' ,
@@ -72,14 +71,14 @@ describe('Close', () => {
7271 } )
7372 } )
7473
75- test ( 'Close with invalid reason' , ( ) => {
74+ test ( 'Close with invalid reason' , ( t ) => {
7675 const server = new WebSocketServer ( { port : 0 } )
7776
7877 const ws = new WebSocket ( `ws://localhost:${ server . address ( ) . port } ` )
7978
8079 return new Promise ( ( resolve ) => {
8180 ws . addEventListener ( 'open' , ( ) => {
82- assert . throws (
81+ t . assert . throws (
8382 ( ) => ws . close ( 1000 , 'a' . repeat ( 124 ) ) ,
8483 {
8584 name : 'SyntaxError' ,
@@ -94,14 +93,14 @@ describe('Close', () => {
9493 } )
9594 } )
9695
97- test ( 'Close with no code or reason' , ( ) => {
96+ test ( 'Close with no code or reason' , ( t ) => {
9897 const server = new WebSocketServer ( { port : 0 } )
9998
10099 return new Promise ( ( resolve ) => {
101100 server . on ( 'connection' , ( ws ) => {
102101 ws . on ( 'close' , ( code , reason ) => {
103- assert . equal ( code , 1005 )
104- assert . deepStrictEqual ( reason , Buffer . alloc ( 0 ) )
102+ t . assert . strictEqual ( code , 1005 )
103+ t . assert . deepStrictEqual ( reason , Buffer . alloc ( 0 ) )
105104 server . close ( )
106105 resolve ( )
107106 } )
@@ -112,14 +111,14 @@ describe('Close', () => {
112111 } )
113112 } )
114113
115- test ( 'Close with a 3000 status code' , ( ) => {
114+ test ( 'Close with a 3000 status code' , ( t ) => {
116115 const server = new WebSocketServer ( { port : 0 } )
117116
118117 return new Promise ( ( resolve ) => {
119118 server . on ( 'connection' , ( ws ) => {
120119 ws . on ( 'close' , ( code , reason ) => {
121- assert . equal ( code , 3000 )
122- assert . deepStrictEqual ( reason , Buffer . alloc ( 0 ) )
120+ t . assert . strictEqual ( code , 3000 )
121+ t . assert . deepStrictEqual ( reason , Buffer . alloc ( 0 ) )
123122 server . close ( )
124123 resolve ( )
125124 } )
0 commit comments