1
1
import { delay } from 'nanodelay'
2
2
import { spyOn } from 'nanospy'
3
- import { test } from 'uvu '
4
- import { equal , is , not , ok , throws , type } from 'uvu/assert '
3
+ import { deepStrictEqual , doesNotThrow , equal , ok , throws } from 'node:assert '
4
+ import { test } from 'node:test '
5
5
6
6
import {
7
7
BaseNode ,
@@ -54,19 +54,19 @@ test('saves all arguments', () => {
54
54
let node = new BaseNode ( 'client' , log , pair . left , options )
55
55
56
56
equal ( node . localNodeId , 'client' )
57
- is ( node . log , log )
58
- is ( node . connection , pair . left )
59
- is ( node . options , options )
57
+ equal ( node . log , log )
58
+ equal ( node . connection , pair . left )
59
+ equal ( node . options , options )
60
60
} )
61
61
62
62
test ( 'allows to miss options' , ( ) => {
63
- equal ( createNode ( ) . options , { } )
63
+ deepStrictEqual ( createNode ( ) . options , { } )
64
64
} )
65
65
66
66
test ( 'has protocol version' , ( ) => {
67
67
let node = createNode ( )
68
- type ( node . localProtocol , 'number' )
69
- type ( node . minProtocol , 'number' )
68
+ equal ( typeof node . localProtocol , 'number' )
69
+ equal ( typeof node . minProtocol , 'number' )
70
70
ok ( node . localProtocol >= node . minProtocol )
71
71
} )
72
72
@@ -90,20 +90,20 @@ test('destroys connection on destroy', () => {
90
90
let destroy = spyOn ( node . connection , 'destroy' )
91
91
92
92
node . destroy ( )
93
- equal ( disconnect . calls , [ ] )
93
+ deepStrictEqual ( disconnect . calls , [ ] )
94
94
equal ( destroy . callCount , 1 )
95
95
} )
96
96
97
97
test ( 'disconnects on destroy' , async ( ) => {
98
98
let node = createNode ( )
99
99
await node . connection . connect ( )
100
100
node . destroy ( )
101
- is ( node . connection . connected , false )
101
+ equal ( node . connection . connected , false )
102
102
} )
103
103
104
104
test ( 'does not throw error on send to disconnected connection' , ( ) => {
105
105
let node = createNode ( )
106
- not . throws ( ( ) => {
106
+ doesNotThrow ( ( ) => {
107
107
privateMethods ( node ) . sendDuilian ( )
108
108
} )
109
109
} )
@@ -112,16 +112,16 @@ test('sends messages to connection', async () => {
112
112
let pair = await createTest ( )
113
113
privateMethods ( pair . leftNode ) . send ( [ 'test' ] )
114
114
await pair . wait ( )
115
- equal ( pair . leftSent , [ [ 'test' ] ] )
115
+ deepStrictEqual ( pair . leftSent , [ [ 'test' ] ] )
116
116
} )
117
117
118
118
test ( 'has connection state' , async ( ) => {
119
119
let node = createNode ( )
120
- is ( node . connected , false )
120
+ equal ( node . connected , false )
121
121
await node . connection . connect ( )
122
- is ( node . connected , true )
122
+ equal ( node . connected , true )
123
123
node . connection . disconnect ( )
124
- is ( node . connected , false )
124
+ equal ( node . connected , false )
125
125
} )
126
126
127
127
test ( 'has state' , async ( ) => {
@@ -160,7 +160,7 @@ test('has state', async () => {
160
160
equal ( node . state , 'synchronized' )
161
161
await node . log . add ( { type : 'c' } )
162
162
node . connection . disconnect ( )
163
- equal ( states , [
163
+ deepStrictEqual ( states , [
164
164
'connecting' ,
165
165
'synchronized' ,
166
166
'sending' ,
@@ -229,7 +229,7 @@ test('stops timeouts on disconnect', async () => {
229
229
230
230
await delay ( 50 )
231
231
privateMethods ( node ) . startTimeout ( )
232
- is ( error , undefined )
232
+ equal ( error , undefined )
233
233
} )
234
234
235
235
test ( 'accepts already connected connection' , async ( ) => {
@@ -238,7 +238,7 @@ test('accepts already connected connection', async () => {
238
238
await pair . left . connect ( )
239
239
node = new BaseNode ( 'client' , TestTime . getLog ( ) , pair . left )
240
240
await node . initializing
241
- is ( node . connected , true )
241
+ equal ( node . connected , true )
242
242
} )
243
243
244
244
test ( 'receives errors from connection' , async ( ) => {
@@ -251,8 +251,8 @@ test('receives errors from connection', async () => {
251
251
let error = new Error ( 'test' )
252
252
emit ( pair . left , 'error' , error )
253
253
254
- is ( pair . leftNode . connected , false )
255
- equal ( pair . leftEvents , [ [ 'connect' ] , [ 'disconnect' , 'error' ] ] )
254
+ equal ( pair . leftNode . connected , false )
255
+ deepStrictEqual ( pair . leftEvents , [ [ 'connect' ] , [ 'disconnect' , 'error' ] ] )
256
256
equal ( emitted , error )
257
257
} )
258
258
@@ -271,8 +271,8 @@ test('cancels error catching', async () => {
271
271
} catch ( e ) {
272
272
catched = e
273
273
}
274
- is ( emitted , undefined )
275
- is ( catched , error )
274
+ equal ( emitted , undefined )
275
+ equal ( catched , error )
276
276
} )
277
277
278
278
test ( 'does not fall on sync without connection' , async ( ) => {
@@ -285,9 +285,9 @@ test('receives format errors from connection', async () => {
285
285
privateMethods ( error ) . received = 'options'
286
286
emit ( pair . left , 'error' , error )
287
287
await pair . wait ( )
288
- is ( pair . leftNode . connected , false )
289
- equal ( pair . leftEvents , [ [ 'connect' ] , [ 'disconnect' , 'error' ] ] )
290
- equal ( pair . leftSent , [ [ 'error' , 'wrong-format' , 'options' ] ] )
288
+ equal ( pair . leftNode . connected , false )
289
+ deepStrictEqual ( pair . leftEvents , [ [ 'connect' ] , [ 'disconnect' , 'error' ] ] )
290
+ deepStrictEqual ( pair . leftSent , [ [ 'error' , 'wrong-format' , 'options' ] ] )
291
291
} )
292
292
293
293
test ( 'throws error by default' , async ( ) => {
@@ -313,8 +313,6 @@ test('disconnect on the error during send', async () => {
313
313
}
314
314
privateMethods ( pair . leftNode ) . send ( [ 'ping' , 0 ] )
315
315
await delay ( 1 )
316
- is ( pair . leftNode . connected , false )
317
- equal ( errors , [ error ] )
316
+ equal ( pair . leftNode . connected , false )
317
+ deepStrictEqual ( errors , [ error ] )
318
318
} )
319
-
320
- test . run ( )
0 commit comments