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 ( '..' )
@@ -12,13 +12,13 @@ const crypto = require('node:crypto')
12
12
const streamToNull = require ( '../lib/stream-consumer' )
13
13
14
14
// skipping on Github Actions because it takes too long
15
- test ( 'should upload a big file in constant memory' , { skip : process . env . CI } , function ( t ) {
15
+ test ( 'should upload a big file in constant memory' , { skip : process . env . CI } , function ( t , done ) {
16
16
t . plan ( 10 )
17
17
18
18
const fastify = Fastify ( )
19
19
const hashInput = crypto . createHash ( 'sha256' )
20
20
21
- t . teardown ( fastify . close . bind ( fastify ) )
21
+ t . after ( ( ) => fastify . close ( ) )
22
22
23
23
fastify . register ( multipart , {
24
24
limits : {
@@ -28,23 +28,23 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
28
28
} )
29
29
30
30
fastify . post ( '/' , async function ( req , reply ) {
31
- t . ok ( req . isMultipart ( ) )
31
+ t . assert . ok ( req . isMultipart ( ) )
32
32
33
33
for await ( const part of req . parts ( ) ) {
34
34
if ( part . file ) {
35
- t . equal ( part . type , 'file' )
36
- t . equal ( part . fieldname , 'upload' )
37
- t . equal ( part . filename , 'random-data' )
38
- t . equal ( part . encoding , '7bit' )
39
- t . equal ( part . mimetype , 'binary/octet-stream' )
35
+ t . assert . strictEqual ( part . type , 'file' )
36
+ t . assert . strictEqual ( part . fieldname , 'upload' )
37
+ t . assert . strictEqual ( part . filename , 'random-data' )
38
+ t . assert . strictEqual ( part . encoding , '7bit' )
39
+ t . assert . strictEqual ( part . mimetype , 'binary/octet-stream' )
40
40
41
41
await streamToNull ( part . file )
42
42
}
43
43
}
44
44
45
45
const memory = process . memoryUsage ( )
46
- t . ok ( memory . rss < 500 * 1024 * 1024 )
47
- t . ok ( memory . heapTotal < 500 * 1024 * 1024 )
46
+ t . assert . ok ( memory . rss < 500 * 1024 * 1024 )
47
+ t . assert . ok ( memory . heapTotal < 500 * 1024 * 1024 )
48
48
49
49
reply . send ( )
50
50
} )
@@ -66,7 +66,7 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
66
66
total -= n
67
67
68
68
if ( total === 0 ) {
69
- t . pass ( 'finished generating' )
69
+ t . assert . ok ( 'finished generating' )
70
70
hashInput . end ( )
71
71
this . push ( null )
72
72
}
@@ -88,12 +88,18 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
88
88
method : 'POST'
89
89
}
90
90
91
- const req = http . request ( opts , ( ) => { fastify . close ( noop ) } )
91
+ const req = http . request ( opts , ( res ) => {
92
+ res . on ( 'data' , ( ) => { } )
93
+
94
+ res . on ( 'end' , ( ) => {
95
+ fastify . close ( ( ) => {
96
+ done ( )
97
+ } )
98
+ } )
99
+ } )
92
100
93
101
pump ( form , req , function ( err ) {
94
- t . error ( err , 'client pump: no err' )
102
+ t . assert . ifError ( err , 'client pump: no err' )
95
103
} )
96
104
} )
97
105
} )
98
-
99
- function noop ( ) { }
0 commit comments