Skip to content

Commit e236d1f

Browse files
authored
Updated to Fastify v4 (#344)
* Updated to Fastify v4 * drop old nodes * fixed tests for Node v18 Signed-off-by: Matteo Collina <[email protected]>
1 parent 84d707b commit e236d1f

19 files changed

+120
-259
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [10.x, 12.x, 14.x, 16.x]
19+
node-version: [14.x, 16.x, 18.x]
2020
os: [macos-latest, ubuntu-latest, windows-latest]
2121

2222
steps:

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,6 @@ function fastifyMultipart (fastify, options, done) {
555555
}
556556

557557
module.exports = fp(fastifyMultipart, {
558-
fastify: '>= 0.39.0',
559-
name: 'fastify-multipart'
558+
fastify: '4.x',
559+
name: '@fastify/multipart'
560560
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"eslint-plugin-node": "^11.1.0",
2626
"eslint-plugin-promise": "^5.1.0",
2727
"eslint-plugin-typescript": "^0.14.0",
28-
"fastify": "^3.24.1",
28+
"fastify": "^4.0.0-rc.2",
2929
"form-data": "^4.0.0",
3030
"h2url": "^0.2.0",
3131
"noop-stream": "^0.1.0",

test/big.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
4343
reply.send()
4444
})
4545

46-
fastify.listen(0, function () {
46+
fastify.listen({ port: 0 }, function () {
4747
const knownLength = 1024 * 1024 * 1024
4848
let total = knownLength
4949
const form = new FormData({ maxDataSize: total })

test/legacy/append-body.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('addToBody option', { skip: process.platform === 'win32' }, t => {
3333
reply.send('ok')
3434
})
3535

36-
fastify.listen(0, function () {
36+
fastify.listen({ port: 0 }, function () {
3737
// request
3838
const form = new FormData()
3939
const opts = {
@@ -78,7 +78,7 @@ test('addToBody with limit exceeded', { skip: process.platform === 'win32' }, t
7878
reply.send('ok')
7979
})
8080

81-
fastify.listen(0, function () {
81+
fastify.listen({ port: 0 }, function () {
8282
// request
8383
const form = new FormData()
8484
const opts = {
@@ -151,7 +151,7 @@ test('addToBody option and multiple files', { skip: process.platform === 'win32'
151151
reply.send('ok')
152152
})
153153

154-
fastify.listen(0, function () {
154+
fastify.listen({ port: 0 }, function () {
155155
// request
156156
const form = new FormData()
157157
const opts = {
@@ -217,7 +217,7 @@ test('addToBody option and multiple files in one field', { skip: process.platfor
217217
reply.send('ok')
218218
})
219219

220-
fastify.listen(0, function () {
220+
fastify.listen({ port: 0 }, function () {
221221
// request
222222
const form = new FormData()
223223
const opts = {
@@ -266,7 +266,7 @@ test('addToBody option and multiple strings in one field', { skip: process.platf
266266
reply.send('ok')
267267
})
268268

269-
fastify.listen(0, function () {
269+
fastify.listen({ port: 0 }, function () {
270270
// request
271271
const form = new FormData()
272272
const opts = {
@@ -324,7 +324,7 @@ test('addToBody option and custom stream management', { skip: process.platform =
324324
reply.send('ok')
325325
})
326326

327-
fastify.listen(0, function () {
327+
fastify.listen({ port: 0 }, function () {
328328
// request
329329
const form = new FormData()
330330
const opts = {
@@ -382,7 +382,7 @@ test('addToBody option with promise', { skip: process.platform === 'win32' }, t
382382
reply.send('ok')
383383
})
384384

385-
fastify.listen(0, function () {
385+
fastify.listen({ port: 0 }, function () {
386386
// request
387387
const form = new FormData()
388388
const opts = {
@@ -428,7 +428,7 @@ test('addToBody option with promise in error', { skip: process.platform === 'win
428428
t.fail('should not execute the handler')
429429
})
430430

431-
fastify.listen(0, function () {
431+
fastify.listen({ port: 0 }, function () {
432432
// request
433433
const form = new FormData()
434434
const opts = {
@@ -499,7 +499,7 @@ test('addToBody with shared schema', { skip: process.platform === 'win32' }, (t)
499499
})
500500
})
501501

502-
fastify.listen(0, function () {
502+
fastify.listen({ port: 0 }, function () {
503503
// request
504504
const form = new FormData()
505505
const opts = {
@@ -569,7 +569,7 @@ test('addToBody with shared schema (async/await)', { skip: process.platform ===
569569
reply.send('ok')
570570
})
571571

572-
await fastify.listen(0)
572+
await fastify.listen({ port: 0 })
573573

574574
// request
575575
const form = new FormData()
@@ -627,7 +627,7 @@ test('addToBody with shared schema error', { skip: process.platform === 'win32'
627627
reply.send('ok')
628628
})
629629

630-
fastify.listen(0, function () {
630+
fastify.listen({ port: 0 }, function () {
631631
// request
632632
const form = new FormData()
633633
const opts = {
@@ -690,7 +690,7 @@ test('addToBody without files and shared schema', { skip: process.platform === '
690690
reply.send('ok')
691691
})
692692

693-
fastify.listen(0, function () {
693+
fastify.listen({ port: 0 }, function () {
694694
// request
695695
const form = new FormData()
696696
const opts = {
@@ -728,7 +728,7 @@ test('addToBody option does not change behaviour on not-multipart request', { sk
728728
fastify.get('/', async (req, rep) => { rep.send('hello') })
729729
fastify.post('/', function (req, reply) { })
730730

731-
fastify.listen(0, function () {
731+
fastify.listen({ port: 0 }, function () {
732732
fastify.inject({
733733
method: 'GET',
734734
url: '/',
@@ -758,7 +758,7 @@ test('addToBody with __proto__ field', t => {
758758
t.fail('should not be called')
759759
})
760760

761-
fastify.listen(0, function () {
761+
fastify.listen({ port: 0 }, function () {
762762
// request
763763
const form = new FormData()
764764
const opts = {
@@ -804,7 +804,7 @@ test('addToBody with constructor field', t => {
804804
t.fail('should not be called')
805805
})
806806

807-
fastify.listen(0, function () {
807+
fastify.listen({ port: 0 }, function () {
808808
// request
809809
const form = new FormData()
810810
const opts = {

test/legacy/big.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
6262
}
6363
})
6464

65-
fastify.listen(0, function () {
65+
fastify.listen({ port: 0 }, function () {
6666
const knownLength = 1024 * 1024 * 1024
6767
let total = knownLength
6868
const form = new FormData({ maxDataSize: total })

test/legacy/multipart.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test('should parse forms', { skip: process.platform === 'win32' }, function (t)
5050
}
5151
})
5252

53-
fastify.listen(0, function () {
53+
fastify.listen({ port: 0 }, function () {
5454
// request
5555
const form = new FormData()
5656
const opts = {
@@ -110,7 +110,7 @@ test('should call finished when both files are pumped', { skip: process.platform
110110
}
111111
})
112112

113-
fastify.listen(0, function () {
113+
fastify.listen({ port: 0 }, function () {
114114
// request
115115
const form = new FormData()
116116
const opts = {
@@ -172,7 +172,7 @@ test('should call finished if one of the streams closes prematurely', { skip: pr
172172
}
173173
})
174174

175-
fastify.listen(0, function () {
175+
fastify.listen({ port: 0 }, function () {
176176
// request
177177
const form = new FormData()
178178
const opts = {
@@ -229,7 +229,7 @@ test('should error if it is not multipart', { skip: process.platform === 'win32'
229229
}
230230
})
231231

232-
fastify.listen(0, function () {
232+
fastify.listen({ port: 0 }, function () {
233233
// request
234234
const opts = {
235235
protocol: 'http:',
@@ -266,7 +266,7 @@ test('should error if handler is not a function', { skip: process.platform === '
266266
})
267267
})
268268

269-
fastify.listen(0, function () {
269+
fastify.listen({ port: 0 }, function () {
270270
// request
271271
const form = new FormData()
272272
const opts = {
@@ -306,7 +306,7 @@ test('should error if callback is not a function', { skip: process.platform ===
306306
function handler () {}
307307
})
308308

309-
fastify.listen(0, function () {
309+
fastify.listen({ port: 0 }, function () {
310310
// request
311311
const form = new FormData()
312312
const opts = {
@@ -353,7 +353,7 @@ test('should error if it is invalid multipart', { skip: process.platform === 'wi
353353
}
354354
})
355355

356-
fastify.listen(0, function () {
356+
fastify.listen({ port: 0 }, function () {
357357
// request
358358
const form = new FormData()
359359
const opts = {
@@ -397,7 +397,7 @@ test('should override options', { skip: process.platform === 'win32' }, function
397397
}
398398
})
399399

400-
fastify.listen(0, function () {
400+
fastify.listen({ port: 0 }, function () {
401401
// request
402402
const form = new FormData()
403403
const opts = {
@@ -450,7 +450,7 @@ test('should not allow __proto__', { skip: process.platform === 'win32' }, funct
450450
}
451451
})
452452

453-
fastify.listen(0, function () {
453+
fastify.listen({ port: 0 }, function () {
454454
// request
455455
const form = new FormData()
456456
const opts = {
@@ -504,7 +504,7 @@ test('should not allow constructor', { skip: process.platform === 'win32' }, fun
504504
}
505505
})
506506

507-
fastify.listen(0, function () {
507+
fastify.listen({ port: 0 }, function () {
508508
// request
509509
const form = new FormData()
510510
const opts = {

test/multipart-attach-body.test.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
'use strict'
22

3-
const util = require('util')
43
const test = require('tap').test
54
const FormData = require('form-data')
65
const Fastify = require('fastify')
76
const multipart = require('..')
87
const http = require('http')
98
const path = require('path')
109
const fs = require('fs')
11-
const stream = require('stream')
1210
const { once } = require('events')
13-
const pump = util.promisify(stream.pipeline)
1411

1512
const filePath = path.join(__dirname, '../README.md')
1613

@@ -37,7 +34,7 @@ test('should be able to attach all parsed fields and files and make it accessibl
3734
reply.code(200).send()
3835
})
3936

40-
await fastify.listen(0)
37+
await fastify.listen({ port: 0 })
4138

4239
// request
4340
const form = new FormData()
@@ -53,12 +50,7 @@ test('should be able to attach all parsed fields and files and make it accessibl
5350
const req = http.request(opts)
5451
form.append('upload', fs.createReadStream(filePath))
5552
form.append('hello', 'world')
56-
57-
try {
58-
await pump(form, req)
59-
} catch (error) {
60-
t.error(error, 'formData request pump: no err')
61-
}
53+
form.pipe(req)
6254

6355
const [res] = await once(req, 'response')
6456
t.equal(res.statusCode, 200)
@@ -95,7 +87,7 @@ test('should be able to define a custom "onFile" handler', async function (t) {
9587
reply.code(200).send()
9688
})
9789

98-
await fastify.listen(0)
90+
await fastify.listen({ port: 0 })
9991

10092
// request
10193
const form = new FormData()
@@ -111,12 +103,7 @@ test('should be able to define a custom "onFile" handler', async function (t) {
111103
const req = http.request(opts)
112104
form.append('upload', fs.createReadStream(filePath))
113105
form.append('hello', 'world')
114-
115-
try {
116-
await pump(form, req)
117-
} catch (error) {
118-
t.error(error, 'formData request pump: no err')
119-
}
106+
form.pipe(req)
120107

121108
const [res] = await once(req, 'response')
122109
t.equal(res.statusCode, 200)
@@ -137,7 +124,7 @@ test('should not process requests with content-type other than multipart', funct
137124
return { hello: req.body.name }
138125
})
139126

140-
fastify.listen(0, function () {
127+
fastify.listen({ port: 0 }, function () {
141128
const opts = {
142129
protocol: 'http:',
143130
hostname: 'localhost',

test/multipart-big-stream.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
'use strict'
22

3-
const util = require('util')
43
const test = require('tap').test
54
const FormData = require('form-data')
65
const Fastify = require('fastify')
76
const multipart = require('..')
87
const http = require('http')
98
const crypto = require('crypto')
109
const { Readable } = require('readable-stream')
11-
const stream = require('stream')
12-
const pump = util.promisify(stream.pipeline)
1310
const sendToWormhole = require('stream-wormhole')
1411
const EventEmitter = require('events')
1512
const { once } = EventEmitter
@@ -34,7 +31,7 @@ test('should emit fileSize limitation error during streaming', async function (t
3431
}
3532
})
3633

37-
await fastify.listen(0)
34+
await fastify.listen({ port: 0 })
3835

3936
// request
4037
const knownLength = 1024 * 1024 // 1MB
@@ -76,7 +73,7 @@ test('should emit fileSize limitation error during streaming', async function (t
7673
knownLength
7774
})
7875

79-
pump(form, req)
76+
form.pipe(req)
8077

8178
try {
8279
const [res] = await once(req, 'response')

0 commit comments

Comments
 (0)