Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to Fastify v4 #344

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
node-version: [14.x, 16.x, 18.x]
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,6 @@ function fastifyMultipart (fastify, options, done) {
}

module.exports = fp(fastifyMultipart, {
fastify: '>= 0.39.0',
name: 'fastify-multipart'
fastify: '4.x',
name: '@fastify/multipart'
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-typescript": "^0.14.0",
"fastify": "^3.24.1",
"fastify": "^4.0.0-rc.2",
"form-data": "^4.0.0",
"h2url": "^0.2.0",
"noop-stream": "^0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion test/big.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
reply.send()
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
const knownLength = 1024 * 1024 * 1024
let total = knownLength
const form = new FormData({ maxDataSize: total })
Expand Down
30 changes: 15 additions & 15 deletions test/legacy/append-body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('addToBody option', { skip: process.platform === 'win32' }, t => {
reply.send('ok')
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -78,7 +78,7 @@ test('addToBody with limit exceeded', { skip: process.platform === 'win32' }, t
reply.send('ok')
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -151,7 +151,7 @@ test('addToBody option and multiple files', { skip: process.platform === 'win32'
reply.send('ok')
})

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

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

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -324,7 +324,7 @@ test('addToBody option and custom stream management', { skip: process.platform =
reply.send('ok')
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -382,7 +382,7 @@ test('addToBody option with promise', { skip: process.platform === 'win32' }, t
reply.send('ok')
})

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

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -499,7 +499,7 @@ test('addToBody with shared schema', { skip: process.platform === 'win32' }, (t)
})
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -569,7 +569,7 @@ test('addToBody with shared schema (async/await)', { skip: process.platform ===
reply.send('ok')
})

await fastify.listen(0)
await fastify.listen({ port: 0 })

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

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -690,7 +690,7 @@ test('addToBody without files and shared schema', { skip: process.platform === '
reply.send('ok')
})

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

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
fastify.inject({
method: 'GET',
url: '/',
Expand Down Expand Up @@ -758,7 +758,7 @@ test('addToBody with __proto__ field', t => {
t.fail('should not be called')
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -804,7 +804,7 @@ test('addToBody with constructor field', t => {
t.fail('should not be called')
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down
2 changes: 1 addition & 1 deletion test/legacy/big.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
const knownLength = 1024 * 1024 * 1024
let total = knownLength
const form = new FormData({ maxDataSize: total })
Expand Down
20 changes: 10 additions & 10 deletions test/legacy/multipart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('should parse forms', { skip: process.platform === 'win32' }, function (t)
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -110,7 +110,7 @@ test('should call finished when both files are pumped', { skip: process.platform
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -172,7 +172,7 @@ test('should call finished if one of the streams closes prematurely', { skip: pr
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -229,7 +229,7 @@ test('should error if it is not multipart', { skip: process.platform === 'win32'
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const opts = {
protocol: 'http:',
Expand Down Expand Up @@ -266,7 +266,7 @@ test('should error if handler is not a function', { skip: process.platform === '
})
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -306,7 +306,7 @@ test('should error if callback is not a function', { skip: process.platform ===
function handler () {}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -353,7 +353,7 @@ test('should error if it is invalid multipart', { skip: process.platform === 'wi
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -397,7 +397,7 @@ test('should override options', { skip: process.platform === 'win32' }, function
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -450,7 +450,7 @@ test('should not allow __proto__', { skip: process.platform === 'win32' }, funct
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -504,7 +504,7 @@ test('should not allow constructor', { skip: process.platform === 'win32' }, fun
}
})

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down
23 changes: 5 additions & 18 deletions test/multipart-attach-body.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
'use strict'

const util = require('util')
const test = require('tap').test
const FormData = require('form-data')
const Fastify = require('fastify')
const multipart = require('..')
const http = require('http')
const path = require('path')
const fs = require('fs')
const stream = require('stream')
const { once } = require('events')
const pump = util.promisify(stream.pipeline)

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

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

await fastify.listen(0)
await fastify.listen({ port: 0 })

// request
const form = new FormData()
Expand All @@ -53,12 +50,7 @@ test('should be able to attach all parsed fields and files and make it accessibl
const req = http.request(opts)
form.append('upload', fs.createReadStream(filePath))
form.append('hello', 'world')

try {
await pump(form, req)
} catch (error) {
t.error(error, 'formData request pump: no err')
}
form.pipe(req)

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

await fastify.listen(0)
await fastify.listen({ port: 0 })

// request
const form = new FormData()
Expand All @@ -111,12 +103,7 @@ test('should be able to define a custom "onFile" handler', async function (t) {
const req = http.request(opts)
form.append('upload', fs.createReadStream(filePath))
form.append('hello', 'world')

try {
await pump(form, req)
} catch (error) {
t.error(error, 'formData request pump: no err')
}
form.pipe(req)

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

fastify.listen(0, function () {
fastify.listen({ port: 0 }, function () {
const opts = {
protocol: 'http:',
hostname: 'localhost',
Expand Down
7 changes: 2 additions & 5 deletions test/multipart-big-stream.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
'use strict'

const util = require('util')
const test = require('tap').test
const FormData = require('form-data')
const Fastify = require('fastify')
const multipart = require('..')
const http = require('http')
const crypto = require('crypto')
const { Readable } = require('readable-stream')
const stream = require('stream')
const pump = util.promisify(stream.pipeline)
const sendToWormhole = require('stream-wormhole')
const EventEmitter = require('events')
const { once } = EventEmitter
Expand All @@ -34,7 +31,7 @@ test('should emit fileSize limitation error during streaming', async function (t
}
})

await fastify.listen(0)
await fastify.listen({ port: 0 })

// request
const knownLength = 1024 * 1024 // 1MB
Expand Down Expand Up @@ -76,7 +73,7 @@ test('should emit fileSize limitation error during streaming', async function (t
knownLength
})

pump(form, req)
form.pipe(req)

try {
const [res] = await once(req, 'response')
Expand Down