Skip to content

Commit

Permalink
Updated to Fastify v4 (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina authored May 11, 2022
1 parent ee6c54c commit babc457
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ function middiePlugin (fastify, options, next) {
}

module.exports = fp(middiePlugin, {
fastify: '>=3.0.0',
fastify: '4.x',
name: 'middie'
})
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/connect": "^3.4.33",
"@types/node": "^17.0.0",
"cors": "^2.8.5",
"fastify": "^3.0.0",
"fastify": "^4.0.0-rc.2",
"helmet": "^5.0.0",
"pre-commit": "^1.2.2",
"serve-static": "^1.14.1",
Expand All @@ -49,9 +49,6 @@
"path-to-regexp": "^6.1.0",
"reusify": "^1.0.4"
},
"engines": {
"node": ">=10.0.0"
},
"tsd": {
"directory": "test"
}
Expand Down
12 changes: 6 additions & 6 deletions test/404s.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('run hooks and middleware on default 404', t => {

t.teardown(fastify.close.bind(fastify))

fastify.listen(0, err => {
fastify.listen({ port: 0 }, err => {
t.error(err)

sget({
Expand Down Expand Up @@ -101,7 +101,7 @@ test('run non-encapsulated plugin hooks and middleware on default 404', t => {
reply.send({ hello: 'world' })
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'POST',
Expand Down Expand Up @@ -163,7 +163,7 @@ test('run non-encapsulated plugin hooks and middleware on custom 404', t => {

fastify.register(plugin) // Registering plugin after handler also works

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -245,7 +245,7 @@ test('run hooks and middleware with encapsulated 404', t => {

t.teardown(fastify.close.bind(fastify))

fastify.listen(0, err => {
fastify.listen({ port: 0 }, err => {
t.error(err)

sget({
Expand Down Expand Up @@ -279,7 +279,7 @@ test('run middlewares on default 404', t => {

t.teardown(fastify.close.bind(fastify))

fastify.listen(0, err => {
fastify.listen({ port: 0 }, err => {
t.error(err)

sget({
Expand Down Expand Up @@ -322,7 +322,7 @@ test('run middlewares with encapsulated 404', t => {

t.teardown(fastify.close.bind(fastify))

fastify.listen(0, err => {
fastify.listen({ port: 0 }, err => {
t.error(err)

sget({
Expand Down
28 changes: 14 additions & 14 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('Should support connect style middlewares', t => {
return { hello: 'world' }
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand All @@ -47,7 +47,7 @@ test('Should support connect style middlewares (async await)', async t => {
return { hello: 'world' }
})

const address = await fastify.listen(0)
const address = await fastify.listen({ port: 0 })
return new Promise((resolve, reject) => {
sget({
method: 'GET',
Expand Down Expand Up @@ -76,7 +76,7 @@ test('Should support connect style middlewares (async await after)', async t =>
return { hello: 'world' }
})

const address = await fastify.listen(0)
const address = await fastify.listen({ port: 0 })
return new Promise((resolve, reject) => {
sget({
method: 'GET',
Expand Down Expand Up @@ -109,7 +109,7 @@ test('Should support per path middlewares', t => {
return { hello: 'world' }
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -151,7 +151,7 @@ test('Encapsulation support / 1', t => {
reply.send('ok')
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -187,7 +187,7 @@ test('Encapsulation support / 2', t => {
reply.send('ok')
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -225,7 +225,7 @@ test('Encapsulation support / 3', t => {
reply.send('ok')
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -274,7 +274,7 @@ test('Encapsulation support / 4', t => {
reply.send('ok')
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -343,7 +343,7 @@ test('Encapsulation support / 5', t => {
reply.send('ok')
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -414,7 +414,7 @@ test('Middleware chain', t => {
return { hello: 'world' }
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -459,7 +459,7 @@ test('Middleware chain (with errors) / 1', t => {
return { hello: 'world' }
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -507,7 +507,7 @@ test('Middleware chain (with errors) / 2', t => {
return { hello: 'world' }
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -571,7 +571,7 @@ test('Send a response from a middleware', t => {
t.fail('We should not be here')
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down Expand Up @@ -613,7 +613,7 @@ test('Should support plugin level prefix', t => {
next()
}, { prefix: '/hello' })

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'GET',
Expand Down
4 changes: 2 additions & 2 deletions test/enhance-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test('Should enhance the Node.js core request/response objects', t => {
return { hello: 'world' }
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'POST',
Expand Down Expand Up @@ -63,7 +63,7 @@ test('Should not enhance the Node.js core request/response objects when there ar
return { hello: 'world' }
})

fastify.listen(0, (err, address) => {
fastify.listen({ port: 0 }, (err, address) => {
t.error(err)
sget({
method: 'POST',
Expand Down
10 changes: 5 additions & 5 deletions test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('use a middleware', t => {
reply.send({ hello: 'world' })
})

instance.listen(0, err => {
instance.listen({ port: 0 }, err => {
t.error(err)

t.teardown(instance.server.close.bind(instance.server))
Expand Down Expand Up @@ -61,7 +61,7 @@ test('use cors', t => {
reply.send({ hello: 'world' })
})

instance.listen(0, err => {
instance.listen({ port: 0 }, err => {
t.error(err)

t.teardown(instance.server.close.bind(instance.server))
Expand Down Expand Up @@ -89,7 +89,7 @@ test('use helmet', t => {
reply.send({ hello: 'world' })
})

instance.listen(0, err => {
instance.listen({ port: 0 }, err => {
t.error(err)

t.teardown(instance.server.close.bind(instance.server))
Expand Down Expand Up @@ -118,7 +118,7 @@ test('use helmet and cors', t => {
reply.send({ hello: 'world' })
})

instance.listen(0, err => {
instance.listen({ port: 0 }, err => {
t.error(err)

t.teardown(instance.server.close.bind(instance.server))
Expand Down Expand Up @@ -177,7 +177,7 @@ test('middlewares with prefix', t => {
instance.get('/prefix/', handler)
instance.get('/prefix/inner', handler)

instance.listen(0, err => {
instance.listen({ port: 0 }, err => {
t.error(err)
t.teardown(instance.server.close.bind(instance.server))

Expand Down

0 comments on commit babc457

Please sign in to comment.