Skip to content

Commit

Permalink
Upgrade to fastify v3 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
frikille committed Apr 29, 2020
1 parent f8f5335 commit 55bc912
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 91 deletions.
5 changes: 5 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
update_configs:
- package_manager: "javascript"
directory: "/"
update_schedule: "daily"
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI workflow
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install --ignore-scripts
- name: Test
run: npm test
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

18 changes: 5 additions & 13 deletions formbody.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import * as http from 'http'
import * as fastify from 'fastify'
import { FastifyPlugin } from 'fastify'

declare namespace formBodyPlugin {
interface FormBodyPluginOptions {
bodyLimit?: number
}
export interface FormBodyPluginOptions {
bodyLimit?: number
}

declare let formBodyPlugin: fastify.Plugin<
http.Server,
http.IncomingMessage,
http.ServerResponse,
formBodyPlugin.FormBodyPluginOptions
>
declare const formBodyPlugin: FastifyPlugin<FormBodyPluginOptions>

export = formBodyPlugin
export default formBodyPlugin
2 changes: 1 addition & 1 deletion formbody.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ function formBodyPlugin (fastify, options, next) {
}

module.exports = fp(formBodyPlugin, {
fastify: '^2.0.0',
fastify: '^3.0.0',
name: 'fastify-formbody'
})
13 changes: 13 additions & 0 deletions formbody.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fastify from 'fastify'
import formBodyPlugin, { FormBodyPluginOptions } from './formbody'

const app = fastify()
app.register(formBodyPlugin)

const emptyOpts: FormBodyPluginOptions = {}
app.register(formBodyPlugin, emptyOpts)

const opts: FormBodyPluginOptions = {
bodyLimit: 1000
}
app.register(formBodyPlugin, opts)
18 changes: 7 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "A module for Fastify to parse x-www-form-urlencoded bodies",
"main": "formbody.js",
"scripts": {
"test": "tap test/**/*.test.js",
"test": "standard && tap test/**/*.test.js && tsd",
"test-ci": "tap test/**/*.test.js --coverage-report=html",
"lint": "standard | snazzy",
"lint-ci": "standard",
"codecov": "codecov",
"typescript": "tsc --project ./tsconfig.json"
"typescript": "tsd"
},
"precommit": [
"lint",
Expand All @@ -31,22 +31,18 @@
"homepage": "https://github.com/fastify/fastify-formbody#readme",
"devDependencies": {
"codecov": "^3.1.0",
"fastify": "^2.0.0",
"fastify": "^3.0.0-alpha.1",
"pre-commit": "^1.2.2",
"request": "^2.88.0",
"snazzy": "^8.0.0",
"standard": "^14.0.2",
"tap": "^12.6.5",
"typescript": "^3.2.2"
"typescript": "^3.2.2",
"tsd": "^0.11.0"
},
"dependencies": {
"fastify-plugin": "^1.0.0",
"fastify-plugin": "^2.0.0",
"qs": "^6.5.1"
},
"types": "formbody.d.ts",
"greenkeeper": {
"ignore": [
"tap"
]
}
"types": "formbody.d.ts"
}
53 changes: 24 additions & 29 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ test('succes route succeeds', (t) => {
t.plan(3)
const fastify = Fastify()

fastify
.register(plugin)
.post('/test1', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})
fastify.register(plugin)
fastify.post('/test1', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})

fastify.listen(0, (err) => {
if (err) tap.error(err)
Expand All @@ -37,11 +36,10 @@ test('cannot exceed body limit', (t) => {
t.plan(3)
const fastify = Fastify()

fastify
.register(plugin, { bodyLimit: 10 })
.post('/limited', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})
fastify.register(plugin, { bodyLimit: 10 })
fastify.post('/limited', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})

fastify.listen(0, (err) => {
if (err) tap.error(err)
Expand All @@ -56,7 +54,7 @@ test('cannot exceed body limit', (t) => {
req({ uri: '/limited', form: { foo: payload } }, (err, response, body) => {
t.error(err)
t.strictEqual(response.statusCode, 413)
t.is(JSON.parse(body).message, 'FST_ERR_CTP_BODY_TOO_LARGE: Request body is too large')
t.is(JSON.parse(body).message, 'Request body is too large')
})
})
})
Expand All @@ -72,11 +70,10 @@ test('cannot exceed body limit when Content-Length is not available', (t) => {
setTimeout(next, 1)
})

fastify
.register(plugin, { bodyLimit: 10 })
.post('/limited', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})
fastify.register(plugin, { bodyLimit: 10 })
fastify.post('/limited', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})

fastify.listen(0, (err) => {
if (err) tap.error(err)
Expand All @@ -100,7 +97,7 @@ test('cannot exceed body limit when Content-Length is not available', (t) => {
req({ uri: '/limited', body: payload }, (err, response, body) => {
t.error(err)
t.strictEqual(response.statusCode, 413)
t.is(JSON.parse(body).message, 'FST_ERR_CTP_BODY_TOO_LARGE: Request body is too large')
t.is(JSON.parse(body).message, 'Request body is too large')
})
})
})
Expand All @@ -109,11 +106,10 @@ test('cannot exceed body limit set on Fastify instance', (t) => {
t.plan(3)
const fastify = Fastify({ bodyLimit: 10 })

fastify
.register(plugin)
.post('/limited', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})
fastify.register(plugin)
fastify.post('/limited', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})

fastify.listen(0, (err) => {
if (err) tap.error(err)
Expand All @@ -128,7 +124,7 @@ test('cannot exceed body limit set on Fastify instance', (t) => {
req({ uri: '/limited', form: { foo: payload } }, (err, response, body) => {
t.error(err)
t.strictEqual(response.statusCode, 413)
t.is(JSON.parse(body).message, 'FST_ERR_CTP_BODY_TOO_LARGE: Request body is too large')
t.is(JSON.parse(body).message, 'Request body is too large')
})
})
})
Expand All @@ -137,11 +133,10 @@ test('plugin bodyLimit should overwrite Fastify instance bodyLimit', (t) => {
t.plan(3)
const fastify = Fastify({ bodyLimit: 100000 })

fastify
.register(plugin, { bodyLimit: 10 })
.post('/limited', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})
fastify.register(plugin, { bodyLimit: 10 })
fastify.post('/limited', (req, res) => {
res.send(Object.assign({}, req.body, { message: 'done' }))
})

fastify.listen(0, (err) => {
if (err) tap.error(err)
Expand All @@ -156,7 +151,7 @@ test('plugin bodyLimit should overwrite Fastify instance bodyLimit', (t) => {
req({ uri: '/limited', form: { foo: payload } }, (err, response, body) => {
t.error(err)
t.strictEqual(response.statusCode, 413)
t.is(JSON.parse(body).message, 'FST_ERR_CTP_BODY_TOO_LARGE: Request body is too large')
t.is(JSON.parse(body).message, 'Request body is too large')
})
})
})
10 changes: 0 additions & 10 deletions tsconfig.json

This file was deleted.

9 changes: 0 additions & 9 deletions types.test.ts

This file was deleted.

0 comments on commit 55bc912

Please sign in to comment.