1
1
'use strict'
2
2
3
- const { test } = require ( 'tap' )
3
+ const { describe, test } = require ( 'node:test' )
4
+ const assert = require ( 'node:assert' )
4
5
const { webidl } = require ( '../../lib/fetch/webidl' )
5
6
6
- test ( 'sequence' , ( t ) => {
7
+ test ( 'sequence' , ( ) => {
7
8
const converter = webidl . sequenceConverter (
8
9
webidl . converters . DOMString
9
10
)
10
11
11
- t . same ( converter ( [ 1 , 2 , 3 ] ) , [ '1' , '2' , '3' ] )
12
+ assert . deepStrictEqual ( converter ( [ 1 , 2 , 3 ] ) , [ '1' , '2' , '3' ] )
12
13
13
- t . throws ( ( ) => {
14
+ assert . throws ( ( ) => {
14
15
converter ( 3 )
15
16
} , TypeError , 'disallows non-objects' )
16
17
17
- t . throws ( ( ) => {
18
+ assert . throws ( ( ) => {
18
19
converter ( null )
19
20
} , TypeError )
20
21
21
- t . throws ( ( ) => {
22
+ assert . throws ( ( ) => {
22
23
converter ( undefined )
23
24
} , TypeError )
24
25
25
- t . throws ( ( ) => {
26
+ assert . throws ( ( ) => {
26
27
converter ( { } )
27
28
} , TypeError , 'no Symbol.iterator' )
28
29
29
- t . throws ( ( ) => {
30
+ assert . throws ( ( ) => {
30
31
converter ( {
31
32
[ Symbol . iterator ] : 42
32
33
} )
33
34
} , TypeError , 'invalid Symbol.iterator' )
34
35
35
- t . throws ( ( ) => {
36
+ assert . throws ( ( ) => {
36
37
converter ( webidl . converters . sequence ( {
37
38
[ Symbol . iterator ] ( ) {
38
39
return {
@@ -41,28 +42,24 @@ test('sequence', (t) => {
41
42
}
42
43
} ) )
43
44
} , TypeError , 'invalid generator' )
44
-
45
- t . end ( )
46
45
} )
47
46
48
- test ( 'webidl.dictionaryConverter' , ( t ) => {
49
- t . test ( 'arguments' , ( t ) => {
47
+ describe ( 'webidl.dictionaryConverter' , ( ) => {
48
+ test ( 'arguments' , ( ) => {
50
49
const converter = webidl . dictionaryConverter ( [ ] )
51
50
52
- t . throws ( ( ) => {
51
+ assert . throws ( ( ) => {
53
52
converter ( true )
54
53
} , TypeError )
55
54
56
55
for ( const value of [ { } , undefined , null ] ) {
57
- t . doesNotThrow ( ( ) => {
56
+ assert . doesNotThrow ( ( ) => {
58
57
converter ( value )
59
58
} )
60
59
}
61
-
62
- t . end ( )
63
60
} )
64
61
65
- t . test ( 'required key' , ( t ) => {
62
+ test ( 'required key' , ( ) => {
66
63
const converter = webidl . dictionaryConverter ( [
67
64
{
68
65
converter : ( ) => true ,
@@ -71,57 +68,51 @@ test('webidl.dictionaryConverter', (t) => {
71
68
}
72
69
] )
73
70
74
- t . throws ( ( ) => {
71
+ assert . throws ( ( ) => {
75
72
converter ( { wrongKey : 'key' } )
76
73
} , TypeError )
77
74
78
- t . doesNotThrow ( ( ) => {
75
+ assert . doesNotThrow ( ( ) => {
79
76
converter ( { Key : 'this key was required!' } )
80
77
} )
81
-
82
- t . end ( )
83
78
} )
84
-
85
- t . end ( )
86
79
} )
87
80
88
- test ( 'ArrayBuffer' , ( t ) => {
89
- t . throws ( ( ) => {
81
+ test ( 'ArrayBuffer' , ( ) => {
82
+ assert . throws ( ( ) => {
90
83
webidl . converters . ArrayBuffer ( true )
91
84
} , TypeError )
92
85
93
- t . throws ( ( ) => {
86
+ assert . throws ( ( ) => {
94
87
webidl . converters . ArrayBuffer ( { } )
95
88
} , TypeError )
96
89
97
- t . throws ( ( ) => {
90
+ assert . throws ( ( ) => {
98
91
const sab = new SharedArrayBuffer ( 1024 )
99
92
webidl . converters . ArrayBuffer ( sab , { allowShared : false } )
100
93
} , TypeError )
101
94
102
- t . doesNotThrow ( ( ) => {
95
+ assert . doesNotThrow ( ( ) => {
103
96
const sab = new SharedArrayBuffer ( 1024 )
104
97
webidl . converters . ArrayBuffer ( sab )
105
98
} )
106
99
107
- t . doesNotThrow ( ( ) => {
100
+ assert . doesNotThrow ( ( ) => {
108
101
const ab = new ArrayBuffer ( 8 )
109
102
webidl . converters . ArrayBuffer ( ab )
110
103
} )
111
-
112
- t . end ( )
113
104
} )
114
105
115
- test ( 'TypedArray' , ( t ) => {
116
- t . throws ( ( ) => {
106
+ test ( 'TypedArray' , ( ) => {
107
+ assert . throws ( ( ) => {
117
108
webidl . converters . TypedArray ( 3 )
118
109
} , TypeError )
119
110
120
- t . throws ( ( ) => {
111
+ assert . throws ( ( ) => {
121
112
webidl . converters . TypedArray ( { } )
122
113
} , TypeError )
123
114
124
- t . throws ( ( ) => {
115
+ assert . throws ( ( ) => {
125
116
const uint8 = new Uint8Array ( [ 1 , 2 , 3 ] )
126
117
Object . defineProperty ( uint8 , 'buffer' , {
127
118
get ( ) {
@@ -133,20 +124,18 @@ test('TypedArray', (t) => {
133
124
allowShared : false
134
125
} )
135
126
} , TypeError )
136
-
137
- t . end ( )
138
127
} )
139
128
140
- test ( 'DataView' , ( t ) => {
141
- t . throws ( ( ) => {
129
+ test ( 'DataView' , ( ) => {
130
+ assert . throws ( ( ) => {
142
131
webidl . converters . DataView ( 3 )
143
132
} , TypeError )
144
133
145
- t . throws ( ( ) => {
134
+ assert . throws ( ( ) => {
146
135
webidl . converters . DataView ( { } )
147
136
} , TypeError )
148
137
149
- t . throws ( ( ) => {
138
+ assert . throws ( ( ) => {
150
139
const buffer = new ArrayBuffer ( 16 )
151
140
const view = new DataView ( buffer , 0 )
152
141
@@ -164,39 +153,33 @@ test('DataView', (t) => {
164
153
const buffer = new ArrayBuffer ( 16 )
165
154
const view = new DataView ( buffer , 0 )
166
155
167
- t . equal ( webidl . converters . DataView ( view ) , view )
168
-
169
- t . end ( )
156
+ assert . equal ( webidl . converters . DataView ( view ) , view )
170
157
} )
171
158
172
- test ( 'BufferSource' , ( t ) => {
173
- t . doesNotThrow ( ( ) => {
159
+ test ( 'BufferSource' , ( ) => {
160
+ assert . doesNotThrow ( ( ) => {
174
161
const buffer = new ArrayBuffer ( 16 )
175
162
const view = new DataView ( buffer , 0 )
176
163
177
164
webidl . converters . BufferSource ( view )
178
165
} )
179
166
180
- t . throws ( ( ) => {
167
+ assert . throws ( ( ) => {
181
168
webidl . converters . BufferSource ( 3 )
182
169
} , TypeError )
183
-
184
- t . end ( )
185
170
} )
186
171
187
- test ( 'ByteString' , ( t ) => {
188
- t . doesNotThrow ( ( ) => {
172
+ test ( 'ByteString' , ( ) => {
173
+ assert . doesNotThrow ( ( ) => {
189
174
webidl . converters . ByteString ( '' )
190
175
} )
191
176
192
177
// https://github.com/nodejs/undici/issues/1590
193
- t . throws ( ( ) => {
178
+ assert . throws ( ( ) => {
194
179
const char = String . fromCharCode ( 256 )
195
180
webidl . converters . ByteString ( `invalid${ char } char` )
196
181
} , {
197
182
message : 'Cannot convert argument to a ByteString because the character at ' +
198
183
'index 7 has a value of 256 which is greater than 255.'
199
184
} )
200
-
201
- t . end ( )
202
185
} )
0 commit comments