Skip to content

Commit

Permalink
feat: fastify 4
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Jun 9, 2022
1 parent cec4f40 commit c86bea2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const plugin: FastifyPluginAsync<FastifyFormidableOptions> = async function (fas
}
}

// we do not require this function anymore but we keep it
// we treat ajv to any because we do not want to deal with the ajv@6 and ajv@8 typing problem
export const ajvBinaryFormat = function (ajv: any): void {
ajv.addFormat('binary', {
Expand All @@ -149,7 +150,7 @@ export const ajvBinaryFormat = function (ajv: any): void {
})
}
export const FastifyFormidable = FastifyPlugin(plugin, {
fastify: '3.x',
fastify: '4.x',
name: 'fastify-formidable',
dependencies: []
})
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@
"formidable": "^1.2.2"
},
"devDependencies": {
"@fastify/swagger": "^6.0.0",
"@fastify/swagger": "^7.0.0",
"@types/node": "^17.0.40",
"@types/tap": "^15.0.7",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.0",
"ajv": "^8.11.0",
"eslint": "^7.12.1",
"eslint-config-standard-with-typescript": "^21.0.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.0.0",
"fastify": "^3.19.0",
"fastify": "^4.0.0",
"form-data": "^4.0.0",
"prettier": "^2.3.2",
"tap": "^16.0.0",
Expand Down
14 changes: 14 additions & 0 deletions test/ajv.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Ajv from 'ajv'
import t from 'tap'
import { ajvBinaryFormat } from '../lib'

t.plan(1)
t.test('ajv binary format', function (t) {
t.plan(2)
const ajv = new Ajv()
ajvBinaryFormat(ajv)

const validate = ajv.compile({ type: 'string', format: 'binary' })
t.equal(validate('any string'), true)
t.equal(validate(123), false)
})
4 changes: 2 additions & 2 deletions test/createFastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function createFastify (t: Tap.Test, options: FastifyFormidableOpti
})
})

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

t.teardown(fastify.close)

Expand Down Expand Up @@ -48,7 +48,7 @@ export async function createIntegrationFastify (t: Tap.Test, options: FastifyFor
})
})

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

t.teardown(fastify.close)

Expand Down
2 changes: 1 addition & 1 deletion test/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ t.test('error', function (t) {
})
})

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

const form = new FormData()
form.append('foo', 'bar')
Expand Down
8 changes: 4 additions & 4 deletions test/removeFilesFromBody.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ t.test('removeFilesFromBody', function (t) {
})
})

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

const form = new FormData()
form.append('foo', 'bar')
Expand Down Expand Up @@ -70,7 +70,7 @@ t.test('removeFilesFromBody', function (t) {
})
})

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

const form = new FormData()
form.append('foo', 'bar')
Expand Down Expand Up @@ -107,7 +107,7 @@ t.test('removeFilesFromBody', function (t) {
})
})

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

const form = new FormData()
form.append('foo', 'bar')
Expand Down Expand Up @@ -144,7 +144,7 @@ t.test('removeFilesFromBody', function (t) {
})
})

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

const form = new FormData()
form.append('foo', 'bar')
Expand Down
2 changes: 1 addition & 1 deletion test/warning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ t.test('warning', function (t) {
})
})

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

const form = new FormData()
form.append('foo', 'bar')
Expand Down

0 comments on commit c86bea2

Please sign in to comment.