@@ -10,32 +10,32 @@ import readStream from "./__helper__/readStream"
10
10
import skip from "./__helper__/skipIterations"
11
11
import readLine from "./__helper__/readLine"
12
12
13
- import { Encoder } from "./Encoder"
13
+ import { FormDataEncoder } from "./Encoder"
14
14
15
15
test ( "Has boundary string" , t => {
16
- const encoder = new Encoder ( new FormData ( ) )
16
+ const encoder = new FormDataEncoder ( new FormData ( ) )
17
17
18
18
t . true ( typeof encoder . boundary === "string" )
19
19
} )
20
20
21
21
test ( "Accepts custom boundary as the second argument" , t => {
22
22
const expected = "BoundaryString123"
23
23
24
- const encoder = new Encoder ( new FormData ( ) , expected )
24
+ const encoder = new FormDataEncoder ( new FormData ( ) , expected )
25
25
26
26
t . is ( encoder . boundary , `form-data-boundary-${ expected } ` )
27
27
} )
28
28
29
29
test ( "Has content-type string" , t => {
30
- const encoder = new Encoder ( new FormData ( ) )
30
+ const encoder = new FormDataEncoder ( new FormData ( ) )
31
31
32
32
t . true ( encoder . contentType . startsWith ( "multipart/form-data; boundary=" ) )
33
33
} )
34
34
35
35
test ( "Has content-type string with custom boundary string" , t => {
36
36
const expected = "BoundaryString123"
37
37
38
- const encoder = new Encoder ( new FormData ( ) , expected )
38
+ const encoder = new FormDataEncoder ( new FormData ( ) , expected )
39
39
40
40
t . is (
41
41
encoder . contentType ,
@@ -44,7 +44,7 @@ test("Has content-type string with custom boundary string", t => {
44
44
} )
45
45
46
46
test ( "Has correct headers" , async t => {
47
- const encoder = new Encoder ( new FormData ( ) )
47
+ const encoder = new FormDataEncoder ( new FormData ( ) )
48
48
49
49
t . deepEqual ( encoder . headers , {
50
50
"Content-Type" : `multipart/form-data; boundary=${ encoder . boundary } ` ,
@@ -53,7 +53,7 @@ test("Has correct headers", async t => {
53
53
} )
54
54
55
55
test ( "Yields correct footer for empty FormData" , async t => {
56
- const encoder = new Encoder ( new FormData ( ) )
56
+ const encoder = new FormDataEncoder ( new FormData ( ) )
57
57
58
58
const iterable = readLine ( Readable . from ( encoder ) )
59
59
@@ -63,13 +63,13 @@ test("Yields correct footer for empty FormData", async t => {
63
63
} )
64
64
65
65
test ( "The footer ends with two crlf" , async t => {
66
- const actual = await readStream ( new Encoder ( new FormData ( ) ) , true )
66
+ const actual = await readStream ( new FormDataEncoder ( new FormData ( ) ) , true )
67
67
68
68
t . true ( actual . endsWith ( "\r\n\r\n" ) )
69
69
} )
70
70
71
71
test ( "Returns correct length of the empty FormData content" , async t => {
72
- const encoder = new Encoder ( new FormData ( ) )
72
+ const encoder = new FormDataEncoder ( new FormData ( ) )
73
73
const expected = await readStream ( encoder ) . then ( ( { length} ) => length )
74
74
75
75
t . is < number > ( encoder . getContentLength ( ) , expected )
@@ -81,7 +81,7 @@ test("Returns the length of the FormData content", async t => {
81
81
fd . set ( "field" , "Some string" )
82
82
fd . set ( "file" , new File ( [ "Some content" ] , "file.txt" ) )
83
83
84
- const encoder = new Encoder ( fd )
84
+ const encoder = new FormDataEncoder ( fd )
85
85
86
86
const expected = await readStream ( encoder ) . then ( ( { length} ) => length )
87
87
@@ -93,7 +93,7 @@ test(".values() yields headers as Uint8Array", t => {
93
93
94
94
fd . set ( "field" , "Some value" )
95
95
96
- const iterable = new Encoder ( fd ) . values ( )
96
+ const iterable = new FormDataEncoder ( fd ) . values ( )
97
97
98
98
const { value : actual } = skipSync ( iterable )
99
99
@@ -105,7 +105,7 @@ test(".valeus() yields field as Uint8Array", t => {
105
105
106
106
fd . set ( "field" , "Some value" )
107
107
108
- const { value : actual } = skipSync ( new Encoder ( fd ) . values ( ) , 2 )
108
+ const { value : actual } = skipSync ( new FormDataEncoder ( fd ) . values ( ) , 2 )
109
109
110
110
t . true ( actual instanceof Uint8Array )
111
111
} )
@@ -118,7 +118,7 @@ test(".valeus() yields field's content", t => {
118
118
119
119
fd . set ( "field" , string )
120
120
121
- const { value : actual } = skipSync ( new Encoder ( fd ) . values ( ) , 2 )
121
+ const { value : actual } = skipSync ( new FormDataEncoder ( fd ) . values ( ) , 2 )
122
122
123
123
t . true ( Buffer . from ( actual as Uint8Array ) . equals ( expected ) )
124
124
} )
@@ -130,7 +130,7 @@ test(".values() yields a file as is", async t => {
130
130
131
131
fd . set ( "file" , file )
132
132
133
- const { value : actual } = skipSync ( new Encoder ( fd ) . values ( ) , 2 )
133
+ const { value : actual } = skipSync ( new FormDataEncoder ( fd ) . values ( ) , 2 )
134
134
135
135
t . true ( actual instanceof File )
136
136
t . is ( await ( actual as File ) . text ( ) , await file . text ( ) )
@@ -141,7 +141,7 @@ test("Yields correct headers for a field", async t => {
141
141
142
142
fd . set ( "field" , "Some value" )
143
143
144
- const iterable = readLine ( Readable . from ( new Encoder ( fd ) ) )
144
+ const iterable = readLine ( Readable . from ( new FormDataEncoder ( fd ) ) )
145
145
146
146
const { value} = await skip ( iterable , 2 )
147
147
@@ -155,7 +155,9 @@ test("Yields field's content", async t => {
155
155
156
156
fd . set ( "field" , expected )
157
157
158
- const { value} = await skip ( readLine ( Readable . from ( new Encoder ( fd ) ) ) , 4 )
158
+ const {
159
+ value
160
+ } = await skip ( readLine ( Readable . from ( new FormDataEncoder ( fd ) ) ) , 4 )
159
161
160
162
t . is ( value , expected )
161
163
} )
@@ -165,7 +167,9 @@ test("Yields Content-Disposition header for a File", async t => {
165
167
166
168
fd . set ( "file" , new File ( [ "My hovercraft is full of eels" ] , "file.txt" ) )
167
169
168
- const { value} = await skip ( readLine ( Readable . from ( new Encoder ( fd ) ) ) , 2 )
170
+ const {
171
+ value
172
+ } = await skip ( readLine ( Readable . from ( new FormDataEncoder ( fd ) ) ) , 2 )
169
173
170
174
t . is (
171
175
value ,
@@ -180,7 +184,9 @@ test("Yields Content-Type header for a File", async t => {
180
184
type : "text/plain"
181
185
} )
182
186
183
- const { value} = await skip ( readLine ( Readable . from ( new Encoder ( fd ) ) ) , 3 )
187
+ const {
188
+ value
189
+ } = await skip ( readLine ( Readable . from ( new FormDataEncoder ( fd ) ) ) , 3 )
184
190
185
191
t . is ( value , "Content-Type: text/plain" )
186
192
} )
@@ -192,7 +198,7 @@ test(
192
198
193
199
fd . set ( "file" , new File ( [ "Some content" ] , "file" ) )
194
200
195
- const iterable = readLine ( Readable . from ( new Encoder ( fd ) ) )
201
+ const iterable = readLine ( Readable . from ( new FormDataEncoder ( fd ) ) )
196
202
197
203
const { value} = await skip ( iterable , 3 )
198
204
@@ -208,7 +214,7 @@ test("Yields File's content", async t => {
208
214
209
215
fd . set ( "license" , await fileFromPath ( filePath ) )
210
216
211
- const encoder = new Encoder ( fd )
217
+ const encoder = new FormDataEncoder ( fd )
212
218
const iterable = readLine ( Readable . from ( encoder ) )
213
219
214
220
await skip ( iterable , 4 )
@@ -235,7 +241,7 @@ test("Yields every appended field", async t => {
235
241
fd . append ( "field" , "Some string" )
236
242
fd . append ( "field" , "Some other string" )
237
243
238
- const iterable = readLine ( Readable . from ( new Encoder ( fd ) ) )
244
+ const iterable = readLine ( Readable . from ( new FormDataEncoder ( fd ) ) )
239
245
240
246
const { value : firstFieldDisposition } = await skip ( iterable , 2 )
241
247
@@ -267,7 +273,7 @@ test("Yields every appended File", async t => {
267
273
fd . append ( "file" , firstFile )
268
274
fd . append ( "file" , secondFile )
269
275
270
- const iterable = readLine ( Readable . from ( new Encoder ( fd ) ) )
276
+ const iterable = readLine ( Readable . from ( new FormDataEncoder ( fd ) ) )
271
277
272
278
const { value : firstFileDisposition } = await skip ( iterable , 2 )
273
279
@@ -300,7 +306,7 @@ test("Can be read through using Blob", async t => {
300
306
fd . set ( "field" , "Some field" )
301
307
fd . set ( "file" , await fileFromPath ( "license" , { type : "text/plain" } ) )
302
308
303
- const encoder = new Encoder ( fd )
309
+ const encoder = new FormDataEncoder ( fd )
304
310
const blob = new Blob ( [ ...encoder ] as any [ ] )
305
311
306
312
t . true (
@@ -314,7 +320,7 @@ test(
314
320
"Throws TypeError when the first argument is not a FormData instance" ,
315
321
t => {
316
322
// @ts -expect-error
317
- const trap = ( ) => new Encoder ( { } )
323
+ const trap = ( ) => new FormDataEncoder ( { } )
318
324
319
325
t . throws ( trap , {
320
326
instanceOf : TypeError ,
@@ -325,7 +331,7 @@ test(
325
331
326
332
test ( "Throws TypeError when given boundary is not a string" , t => {
327
333
// @ts -expect-error
328
- const trap = ( ) => new Encoder ( new FormData ( ) , 42 )
334
+ const trap = ( ) => new FormDataEncoder ( new FormData ( ) , 42 )
329
335
330
336
t . throws ( trap , {
331
337
instanceOf : TypeError ,
0 commit comments