1
1
'use strict'
2
2
3
- const { test } = require ( 'tap ' )
3
+ const { test } = require ( 'node:test ' )
4
4
const { parse, safeParse } = require ( '..' )
5
5
6
6
const invalidTypes = [
@@ -17,232 +17,232 @@ const invalidTypes = [
17
17
'text/plain,wrong'
18
18
]
19
19
20
- test ( 'parse' , function ( t ) {
20
+ test ( 'parse' , async function ( t ) {
21
21
t . plan ( 13 + invalidTypes . length )
22
- t . test ( 'should parse basic type' , function ( t ) {
22
+ await t . test ( 'should parse basic type' , function ( t ) {
23
23
t . plan ( 1 )
24
24
const type = parse ( 'text/html' )
25
- t . strictSame ( type . type , 'text/html' )
25
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
26
26
} )
27
27
28
- t . test ( 'should parse with suffix' , function ( t ) {
28
+ await t . test ( 'should parse with suffix' , function ( t ) {
29
29
t . plan ( 1 )
30
30
const type = parse ( 'image/svg+xml' )
31
- t . strictSame ( type . type , 'image/svg+xml' )
31
+ t . assert . deepStrictEqual ( type . type , 'image/svg+xml' )
32
32
} )
33
33
34
- t . test ( 'should parse basic type with surrounding OWS' , function ( t ) {
34
+ await t . test ( 'should parse basic type with surrounding OWS' , function ( t ) {
35
35
t . plan ( 1 )
36
36
const type = parse ( ' text/html ' )
37
- t . strictSame ( type . type , 'text/html' )
37
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
38
38
} )
39
39
40
- t . test ( 'should parse parameters' , function ( t ) {
40
+ await t . test ( 'should parse parameters' , function ( t ) {
41
41
t . plan ( 2 )
42
42
const type = parse ( 'text/html; charset=utf-8; foo=bar' )
43
- t . strictSame ( type . type , 'text/html' )
44
- t . same ( type . parameters , {
43
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
44
+ t . assert . deepEqual ( type . parameters , {
45
45
charset : 'utf-8' ,
46
46
foo : 'bar'
47
47
} )
48
48
} )
49
49
50
- t . test ( 'should parse parameters with extra LWS' , function ( t ) {
50
+ await t . test ( 'should parse parameters with extra LWS' , function ( t ) {
51
51
t . plan ( 2 )
52
52
const type = parse ( 'text/html ; charset=utf-8 ; foo=bar' )
53
- t . strictSame ( type . type , 'text/html' )
54
- t . same ( type . parameters , {
53
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
54
+ t . assert . deepEqual ( type . parameters , {
55
55
charset : 'utf-8' ,
56
56
foo : 'bar'
57
57
} )
58
58
} )
59
59
60
- t . test ( 'should lower-case type' , function ( t ) {
60
+ await t . test ( 'should lower-case type' , function ( t ) {
61
61
t . plan ( 1 )
62
62
const type = parse ( 'IMAGE/SVG+XML' )
63
- t . strictSame ( type . type , 'image/svg+xml' )
63
+ t . assert . deepStrictEqual ( type . type , 'image/svg+xml' )
64
64
} )
65
65
66
- t . test ( 'should lower-case parameter names' , function ( t ) {
66
+ await t . test ( 'should lower-case parameter names' , function ( t ) {
67
67
t . plan ( 2 )
68
68
const type = parse ( 'text/html; Charset=UTF-8' )
69
- t . strictSame ( type . type , 'text/html' )
70
- t . same ( type . parameters , {
69
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
70
+ t . assert . deepEqual ( type . parameters , {
71
71
charset : 'UTF-8'
72
72
} )
73
73
} )
74
74
75
- t . test ( 'should unquote parameter values' , function ( t ) {
75
+ await t . test ( 'should unquote parameter values' , function ( t ) {
76
76
t . plan ( 2 )
77
77
const type = parse ( 'text/html; charset="UTF-8"' )
78
- t . strictSame ( type . type , 'text/html' )
79
- t . same ( type . parameters , {
78
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
79
+ t . assert . deepEqual ( type . parameters , {
80
80
charset : 'UTF-8'
81
81
} )
82
82
} )
83
83
84
- t . test ( 'should unquote parameter values with escapes' , function ( t ) {
84
+ await t . test ( 'should unquote parameter values with escapes' , function ( t ) {
85
85
t . plan ( 2 )
86
86
const type = parse ( 'text/html; charset="UT\\F-\\\\\\"8\\""' )
87
- t . strictSame ( type . type , 'text/html' )
88
- t . same ( type . parameters , {
87
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
88
+ t . assert . deepEqual ( type . parameters , {
89
89
charset : 'UTF-\\"8"'
90
90
} )
91
91
} )
92
92
93
- t . test ( 'should handle balanced quotes' , function ( t ) {
93
+ await t . test ( 'should handle balanced quotes' , function ( t ) {
94
94
t . plan ( 2 )
95
95
const type = parse ( 'text/html; param="charset=\\"utf-8\\"; foo=bar"; bar=foo' )
96
- t . strictSame ( type . type , 'text/html' )
97
- t . same ( type . parameters , {
96
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
97
+ t . assert . deepEqual ( type . parameters , {
98
98
param : 'charset="utf-8"; foo=bar' ,
99
99
bar : 'foo'
100
100
} )
101
101
} )
102
102
103
- invalidTypes . forEach ( function ( type ) {
104
- t . test ( 'should throw on invalid media type ' + type , function ( t ) {
103
+ invalidTypes . forEach ( async function ( type ) {
104
+ await t . test ( 'should throw on invalid media type ' + type , function ( t ) {
105
105
t . plan ( 1 )
106
- t . throws ( parse . bind ( null , type ) , 'invalid media type' )
106
+ t . assert . throws ( parse . bind ( null , type ) , new TypeError ( 'invalid media type' ) )
107
107
} )
108
108
} )
109
109
110
- t . test ( 'should throw on invalid parameter format' , function ( t ) {
110
+ await t . test ( 'should throw on invalid parameter format' , function ( t ) {
111
111
t . plan ( 3 )
112
- t . throws ( parse . bind ( null , 'text/plain; foo="bar' ) , 'invalid parameter format' )
113
- t . throws ( parse . bind ( null , 'text/plain; profile=http://localhost; foo=bar' ) , 'invalid parameter format' )
114
- t . throws ( parse . bind ( null , 'text/plain; profile=http://localhost' ) , 'invalid parameter format' )
112
+ t . assert . throws ( parse . bind ( null , 'text/plain; foo="bar' ) , new TypeError ( 'invalid parameter format' ) )
113
+ t . assert . throws ( parse . bind ( null , 'text/plain; profile=http://localhost; foo=bar' ) , new TypeError ( 'invalid parameter format' ) )
114
+ t . assert . throws ( parse . bind ( null , 'text/plain; profile=http://localhost' ) , new TypeError ( 'invalid parameter format' ) )
115
115
} )
116
116
117
- t . test ( 'should require argument' , function ( t ) {
117
+ await t . test ( 'should require argument' , function ( t ) {
118
118
t . plan ( 1 )
119
119
// @ts -expect-error should reject non-strings
120
- t . throws ( parse . bind ( null ) , 'argument header is required and must be a string' )
120
+ t . assert . throws ( parse . bind ( null ) , new TypeError ( 'argument header is required and must be a string' ) )
121
121
} )
122
122
123
- t . test ( 'should reject non-strings' , function ( t ) {
123
+ await t . test ( 'should reject non-strings' , function ( t ) {
124
124
t . plan ( 1 )
125
125
// @ts -expect-error should reject non-strings
126
- t . throws ( parse . bind ( null , 7 ) , 'argument header is required and must be a string' )
126
+ t . assert . throws ( parse . bind ( null , 7 ) , new TypeError ( 'argument header is required and must be a string' ) )
127
127
} )
128
128
} )
129
129
130
- test ( 'safeParse' , function ( t ) {
130
+ test ( 'safeParse' , async function ( t ) {
131
131
t . plan ( 13 + invalidTypes . length )
132
- t . test ( 'should safeParse basic type' , function ( t ) {
132
+ await t . test ( 'should safeParse basic type' , function ( t ) {
133
133
t . plan ( 1 )
134
134
const type = safeParse ( 'text/html' )
135
- t . strictSame ( type . type , 'text/html' )
135
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
136
136
} )
137
137
138
- t . test ( 'should safeParse with suffix' , function ( t ) {
138
+ await t . test ( 'should safeParse with suffix' , function ( t ) {
139
139
t . plan ( 1 )
140
140
const type = safeParse ( 'image/svg+xml' )
141
- t . strictSame ( type . type , 'image/svg+xml' )
141
+ t . assert . deepStrictEqual ( type . type , 'image/svg+xml' )
142
142
} )
143
143
144
- t . test ( 'should safeParse basic type with surrounding OWS' , function ( t ) {
144
+ await t . test ( 'should safeParse basic type with surrounding OWS' , function ( t ) {
145
145
t . plan ( 1 )
146
146
const type = safeParse ( ' text/html ' )
147
- t . strictSame ( type . type , 'text/html' )
147
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
148
148
} )
149
149
150
- t . test ( 'should safeParse parameters' , function ( t ) {
150
+ await t . test ( 'should safeParse parameters' , function ( t ) {
151
151
t . plan ( 2 )
152
152
const type = safeParse ( 'text/html; charset=utf-8; foo=bar' )
153
- t . strictSame ( type . type , 'text/html' )
154
- t . same ( type . parameters , {
153
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
154
+ t . assert . deepEqual ( type . parameters , {
155
155
charset : 'utf-8' ,
156
156
foo : 'bar'
157
157
} )
158
158
} )
159
159
160
- t . test ( 'should safeParse parameters with extra LWS' , function ( t ) {
160
+ await t . test ( 'should safeParse parameters with extra LWS' , function ( t ) {
161
161
t . plan ( 2 )
162
162
const type = safeParse ( 'text/html ; charset=utf-8 ; foo=bar' )
163
- t . strictSame ( type . type , 'text/html' )
164
- t . same ( type . parameters , {
163
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
164
+ t . assert . deepEqual ( type . parameters , {
165
165
charset : 'utf-8' ,
166
166
foo : 'bar'
167
167
} )
168
168
} )
169
169
170
- t . test ( 'should lower-case type' , function ( t ) {
170
+ await t . test ( 'should lower-case type' , function ( t ) {
171
171
t . plan ( 1 )
172
172
const type = safeParse ( 'IMAGE/SVG+XML' )
173
- t . strictSame ( type . type , 'image/svg+xml' )
173
+ t . assert . deepStrictEqual ( type . type , 'image/svg+xml' )
174
174
} )
175
175
176
- t . test ( 'should lower-case parameter names' , function ( t ) {
176
+ await t . test ( 'should lower-case parameter names' , function ( t ) {
177
177
t . plan ( 2 )
178
178
const type = safeParse ( 'text/html; Charset=UTF-8' )
179
- t . strictSame ( type . type , 'text/html' )
180
- t . same ( type . parameters , {
179
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
180
+ t . assert . deepEqual ( type . parameters , {
181
181
charset : 'UTF-8'
182
182
} )
183
183
} )
184
184
185
- t . test ( 'should unquote parameter values' , function ( t ) {
185
+ await t . test ( 'should unquote parameter values' , function ( t ) {
186
186
t . plan ( 2 )
187
187
const type = safeParse ( 'text/html; charset="UTF-8"' )
188
- t . strictSame ( type . type , 'text/html' )
189
- t . same ( type . parameters , {
188
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
189
+ t . assert . deepEqual ( type . parameters , {
190
190
charset : 'UTF-8'
191
191
} )
192
192
} )
193
193
194
- t . test ( 'should unquote parameter values with escapes' , function ( t ) {
194
+ await t . test ( 'should unquote parameter values with escapes' , function ( t ) {
195
195
t . plan ( 2 )
196
196
const type = safeParse ( 'text/html; charset="UT\\F-\\\\\\"8\\""' )
197
- t . strictSame ( type . type , 'text/html' )
198
- t . same ( type . parameters , {
197
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
198
+ t . assert . deepEqual ( type . parameters , {
199
199
charset : 'UTF-\\"8"'
200
200
} )
201
201
} )
202
202
203
- t . test ( 'should handle balanced quotes' , function ( t ) {
203
+ await t . test ( 'should handle balanced quotes' , function ( t ) {
204
204
t . plan ( 2 )
205
205
const type = safeParse ( 'text/html; param="charset=\\"utf-8\\"; foo=bar"; bar=foo' )
206
- t . strictSame ( type . type , 'text/html' )
207
- t . same ( type . parameters , {
206
+ t . assert . deepStrictEqual ( type . type , 'text/html' )
207
+ t . assert . deepEqual ( type . parameters , {
208
208
param : 'charset="utf-8"; foo=bar' ,
209
209
bar : 'foo'
210
210
} )
211
211
} )
212
212
213
- invalidTypes . forEach ( function ( type ) {
214
- t . test ( 'should return dummyContentType on invalid media type ' + type , function ( t ) {
213
+ invalidTypes . forEach ( async function ( type ) {
214
+ await t . test ( 'should return dummyContentType on invalid media type ' + type , function ( t ) {
215
215
t . plan ( 2 )
216
- t . equal ( safeParse ( type ) . type , '' )
217
- t . equal ( Object . keys ( safeParse ( type ) . parameters ) . length , 0 )
216
+ t . assert . deepStrictEqual ( safeParse ( type ) . type , '' )
217
+ t . assert . deepStrictEqual ( Object . keys ( safeParse ( type ) . parameters ) . length , 0 )
218
218
} )
219
219
} )
220
220
221
- t . test ( 'should return dummyContentType on invalid parameter format' , function ( t ) {
221
+ await t . test ( 'should return dummyContentType on invalid parameter format' , function ( t ) {
222
222
t . plan ( 6 )
223
- t . equal ( safeParse ( 'text/plain; foo="bar' ) . type , '' )
224
- t . equal ( Object . keys ( safeParse ( 'text/plain; foo="bar' ) . parameters ) . length , 0 )
223
+ t . assert . deepStrictEqual ( safeParse ( 'text/plain; foo="bar' ) . type , '' )
224
+ t . assert . deepStrictEqual ( Object . keys ( safeParse ( 'text/plain; foo="bar' ) . parameters ) . length , 0 )
225
225
226
- t . equal ( safeParse ( 'text/plain; profile=http://localhost; foo=bar' ) . type , '' )
227
- t . equal ( Object . keys ( safeParse ( 'text/plain; profile=http://localhost; foo=bar' ) . parameters ) . length , 0 )
226
+ t . assert . deepStrictEqual ( safeParse ( 'text/plain; profile=http://localhost; foo=bar' ) . type , '' )
227
+ t . assert . deepStrictEqual ( Object . keys ( safeParse ( 'text/plain; profile=http://localhost; foo=bar' ) . parameters ) . length , 0 )
228
228
229
- t . equal ( safeParse ( 'text/plain; profile=http://localhost' ) . type , '' )
230
- t . equal ( Object . keys ( safeParse ( 'text/plain; profile=http://localhost' ) . parameters ) . length , 0 )
229
+ t . assert . deepStrictEqual ( safeParse ( 'text/plain; profile=http://localhost' ) . type , '' )
230
+ t . assert . deepStrictEqual ( Object . keys ( safeParse ( 'text/plain; profile=http://localhost' ) . parameters ) . length , 0 )
231
231
} )
232
232
233
- t . test ( 'should return dummyContentType on missing argument' , function ( t ) {
233
+ await t . test ( 'should return dummyContentType on missing argument' , function ( t ) {
234
234
t . plan ( 2 )
235
235
// @ts -expect-error should reject non-strings
236
- t . equal ( safeParse ( ) . type , '' )
236
+ t . assert . deepStrictEqual ( safeParse ( ) . type , '' )
237
237
// @ts -expect-error should reject non-strings
238
- t . equal ( Object . keys ( safeParse ( ) . parameters ) . length , 0 )
238
+ t . assert . deepStrictEqual ( Object . keys ( safeParse ( ) . parameters ) . length , 0 )
239
239
} )
240
240
241
- t . test ( 'should return dummyContentType on non-strings' , function ( t ) {
241
+ await t . test ( 'should return dummyContentType on non-strings' , function ( t ) {
242
242
t . plan ( 2 )
243
243
// @ts -expect-error should reject non-strings
244
- t . equal ( safeParse ( null ) . type , '' )
244
+ t . assert . deepStrictEqual ( safeParse ( null ) . type , '' )
245
245
// @ts -expect-error should reject non-strings
246
- t . equal ( Object . keys ( safeParse ( null ) . parameters ) . length , 0 )
246
+ t . assert . deepStrictEqual ( Object . keys ( safeParse ( null ) . parameters ) . length , 0 )
247
247
} )
248
248
} )
0 commit comments