1
1
'use strict'
2
2
3
- const test = require ( 'tap' ) . test
3
+ const test = require ( 'node:test' )
4
4
const FormData = require ( 'form-data' )
5
5
const Fastify = require ( 'fastify' )
6
6
const multipart = require ( '..' )
@@ -17,38 +17,38 @@ test('should store file on disk, remove on response when attach fields to body i
17
17
t . plan ( 25 )
18
18
19
19
const fastify = Fastify ( )
20
- t . teardown ( fastify . close . bind ( fastify ) )
20
+ t . after ( ( ) => fastify . close ( ) )
21
21
22
22
fastify . register ( multipart , {
23
23
attachFieldsToBody : true
24
24
} )
25
25
26
26
fastify . post ( '/' , async function ( req , reply ) {
27
- t . ok ( req . isMultipart ( ) )
27
+ t . assert . ok ( req . isMultipart ( ) )
28
28
29
29
const files = await req . saveRequestFiles ( )
30
30
31
- t . ok ( files [ 0 ] . filepath )
32
- t . equal ( files [ 0 ] . type , 'file' )
33
- t . equal ( files [ 0 ] . fieldname , 'upload' )
34
- t . equal ( files [ 0 ] . filename , 'README.md' )
35
- t . equal ( files [ 0 ] . encoding , '7bit' )
36
- t . equal ( files [ 0 ] . mimetype , 'text/markdown' )
37
- t . ok ( files [ 0 ] . fields . upload )
38
- t . ok ( files [ 1 ] . filepath )
39
- t . equal ( files [ 1 ] . type , 'file' )
40
- t . equal ( files [ 1 ] . fieldname , 'upload' )
41
- t . equal ( files [ 1 ] . filename , 'README.md' )
42
- t . equal ( files [ 1 ] . encoding , '7bit' )
43
- t . equal ( files [ 1 ] . mimetype , 'text/markdown' )
44
- t . ok ( files [ 1 ] . fields . upload )
45
- t . ok ( files [ 2 ] . filepath )
46
- t . equal ( files [ 2 ] . type , 'file' )
47
- t . equal ( files [ 2 ] . fieldname , 'other' )
48
- t . equal ( files [ 2 ] . filename , 'README.md' )
49
- t . equal ( files [ 2 ] . encoding , '7bit' )
50
- t . equal ( files [ 2 ] . mimetype , 'text/markdown' )
51
- t . ok ( files [ 2 ] . fields . upload )
31
+ t . assert . ok ( files [ 0 ] . filepath )
32
+ t . assert . strictEqual ( files [ 0 ] . type , 'file' )
33
+ t . assert . strictEqual ( files [ 0 ] . fieldname , 'upload' )
34
+ t . assert . strictEqual ( files [ 0 ] . filename , 'README.md' )
35
+ t . assert . strictEqual ( files [ 0 ] . encoding , '7bit' )
36
+ t . assert . strictEqual ( files [ 0 ] . mimetype , 'text/markdown' )
37
+ t . assert . ok ( files [ 0 ] . fields . upload )
38
+ t . assert . ok ( files [ 1 ] . filepath )
39
+ t . assert . strictEqual ( files [ 1 ] . type , 'file' )
40
+ t . assert . strictEqual ( files [ 1 ] . fieldname , 'upload' )
41
+ t . assert . strictEqual ( files [ 1 ] . filename , 'README.md' )
42
+ t . assert . strictEqual ( files [ 1 ] . encoding , '7bit' )
43
+ t . assert . strictEqual ( files [ 1 ] . mimetype , 'text/markdown' )
44
+ t . assert . ok ( files [ 1 ] . fields . upload )
45
+ t . assert . ok ( files [ 2 ] . filepath )
46
+ t . assert . strictEqual ( files [ 2 ] . type , 'file' )
47
+ t . assert . strictEqual ( files [ 2 ] . fieldname , 'other' )
48
+ t . assert . strictEqual ( files [ 2 ] . filename , 'README.md' )
49
+ t . assert . strictEqual ( files [ 2 ] . encoding , '7bit' )
50
+ t . assert . strictEqual ( files [ 2 ] . mimetype , 'text/markdown' )
51
+ t . assert . ok ( files [ 2 ] . fields . upload )
52
52
53
53
await access ( files [ 0 ] . filepath , fs . constants . F_OK )
54
54
await access ( files [ 1 ] . filepath , fs . constants . F_OK )
@@ -63,8 +63,8 @@ test('should store file on disk, remove on response when attach fields to body i
63
63
try {
64
64
await access ( request . tmpUploads [ 0 ] , fs . constants . F_OK )
65
65
} catch ( error ) {
66
- t . equal ( error . code , 'ENOENT' )
67
- t . pass ( 'Temp file was removed after response' )
66
+ t . assert . strictEqual ( error . code , 'ENOENT' )
67
+ t . assert . ok ( 'Temp file was removed after response' )
68
68
ee . emit ( 'response' )
69
69
}
70
70
} )
@@ -89,7 +89,7 @@ test('should store file on disk, remove on response when attach fields to body i
89
89
form . pipe ( req )
90
90
91
91
const [ res ] = await once ( req , 'response' )
92
- t . equal ( res . statusCode , 200 )
92
+ t . assert . strictEqual ( res . statusCode , 200 )
93
93
res . resume ( )
94
94
await once ( res , 'end' )
95
95
await once ( ee , 'response' )
@@ -99,7 +99,7 @@ test('should throw on saving request files when attach fields to body is true bu
99
99
t . plan ( 3 )
100
100
101
101
const fastify = Fastify ( )
102
- t . teardown ( fastify . close . bind ( fastify ) )
102
+ t . after ( ( ) => fastify . close ( ) )
103
103
104
104
fastify . register ( multipart , {
105
105
attachFieldsToBody : true ,
@@ -111,13 +111,13 @@ test('should throw on saving request files when attach fields to body is true bu
111
111
} )
112
112
113
113
fastify . post ( '/' , async function ( req , reply ) {
114
- t . ok ( req . isMultipart ( ) )
114
+ t . assert . ok ( req . isMultipart ( ) )
115
115
116
116
try {
117
117
await req . saveRequestFiles ( )
118
118
reply . code ( 200 ) . send ( )
119
119
} catch ( error ) {
120
- t . ok ( error instanceof fastify . multipartErrors . FileBufferNotFoundError )
120
+ t . assert . ok ( error instanceof fastify . multipartErrors . FileBufferNotFoundError )
121
121
reply . code ( 500 ) . send ( )
122
122
}
123
123
} )
@@ -140,7 +140,7 @@ test('should throw on saving request files when attach fields to body is true bu
140
140
form . pipe ( req )
141
141
142
142
const [ res ] = await once ( req , 'response' )
143
- t . equal ( res . statusCode , 500 )
143
+ t . assert . strictEqual ( res . statusCode , 500 )
144
144
res . resume ( )
145
145
await once ( res , 'end' )
146
146
} )
0 commit comments