Skip to content

Commit 7feac75

Browse files
authored
major: deps and codebase maintenance (#18)
* chore: updated tap * fix: remove deprecation * feat!: update form-data
1 parent 7b9a2d0 commit 7feac75

File tree

6 files changed

+48
-72
lines changed

6 files changed

+48
-72
lines changed

.github/dependabot.yml

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
version: 2
22
updates:
3-
- package-ecosystem: npm
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: "04:00"
8-
open-pull-requests-limit: 10
9-
ignore:
10-
- dependency-name: tap
11-
versions:
12-
- "> 12.7.0"
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
open-pull-requests-limit: 10
8+
9+
- package-ecosystem: "npm"
10+
directory: "/"
11+
schedule:
12+
interval: "weekly"
13+
open-pull-requests-limit: 10

.github/workflows/ci.yml

+9-25
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,16 @@ name: ci
22

33
on:
44
push:
5+
paths-ignore:
6+
- 'docs/**'
7+
- '*.md'
58
pull_request:
6-
7-
env:
8-
CI: true
9+
paths-ignore:
10+
- 'docs/**'
11+
- '*.md'
912

1013
jobs:
1114
test:
12-
runs-on: ${{ matrix.os }}
13-
14-
strategy:
15-
matrix:
16-
node-version: [10, 12, 14, 16]
17-
os: [ubuntu-latest]
18-
19-
steps:
20-
- uses: actions/checkout@v2
21-
22-
- name: Use Node.js
23-
uses: actions/setup-node@v2
24-
with:
25-
node-version: ${{ matrix.node-version }}
26-
27-
- name: Install
28-
run: |
29-
npm install --ignore-scripts
30-
31-
- name: Run tests
32-
run: |
33-
npm test
15+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
16+
with:
17+
lint: true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ dist
104104
.tern-port
105105

106106
package-lock.json
107+
.vscode/

index.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const FormData = require('form-data')
4-
const querystring = require('querystring')
4+
const querystring = require('fast-querystring')
55
const { Readable } = require('stream')
66

77
module.exports = function formMethod (json, opts) {
@@ -13,8 +13,7 @@ module.exports = function formMethod (json, opts) {
1313

1414
const form = new FormData()
1515
const hasFile = Object.keys(json)
16-
.map(unfold.bind(json))
17-
.reduce(flatMap, [])
16+
.flatMap(unfold.bind(json))
1817
.reduce((isFile, { k, v }) => {
1918
const value = getValue(v)
2019
const options = getOptions(v)
@@ -59,12 +58,3 @@ function unfold (k) {
5958
}
6059
return { k, v }
6160
}
62-
63-
// We need to support node 10 till April 2021
64-
function flatMap (acc, unfold) {
65-
if (Array.isArray(unfold)) {
66-
return acc.concat(unfold)
67-
}
68-
acc.push(unfold)
69-
return acc
70-
}

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
"description": "Build a form without headache",
55
"main": "index.js",
66
"scripts": {
7-
"unit": "tap -J test/**/*.test.js --cov",
87
"lint": "standard",
98
"lint:fix": "standard --fix",
10-
"test": "npm run lint && npm run unit"
9+
"test": "tap test/**/*.test.js"
1110
},
1211
"repository": {
1312
"type": "git",
@@ -36,9 +35,10 @@
3635
"light-my-request": "^5.0.0",
3736
"multiparty": "^4.2.1",
3837
"standard": "^17.0.0",
39-
"tap": "^14.10.8"
38+
"tap": "^16.3.0"
4039
},
4140
"dependencies": {
42-
"form-data": "^3.0.0"
41+
"fast-querystring": "^1.0.0",
42+
"form-data": "^4.0.0"
4343
}
4444
}

test/index.test.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ test('application/x-www-form-urlencoded', t => {
2525
let payload = ''
2626
form.payload.on('data', data => { payload += data })
2727
form.payload.on('end', () => {
28-
t.deepEquals(payload, 'field1=value1&field2=value2')
28+
t.strictSame(payload, 'field1=value1&field2=value2')
2929
})
30-
t.deepEquals(form.headers, { 'content-type': 'application/x-www-form-urlencoded' })
30+
t.strictSame(form.headers, { 'content-type': 'application/x-www-form-urlencoded' })
3131
})
3232

3333
test('custom data name', t => {
@@ -40,9 +40,9 @@ test('custom data name', t => {
4040
let payload = ''
4141
form.body.on('data', data => { payload += data })
4242
form.body.on('end', () => {
43-
t.deepEquals(payload, 'field1=value1&field2=value2')
43+
t.strictSame(payload, 'field1=value1&field2=value2')
4444
})
45-
t.deepEquals(form.head, { 'content-type': 'application/x-www-form-urlencoded' })
45+
t.strictSame(form.head, { 'content-type': 'application/x-www-form-urlencoded' })
4646
})
4747

4848
test('application/x-www-form-urlencoded array', t => {
@@ -55,9 +55,9 @@ test('application/x-www-form-urlencoded array', t => {
5555
let payload = ''
5656
form.payload.on('data', data => { payload += data })
5757
form.payload.on('end', () => {
58-
t.deepEquals(payload, 'field1=value1&field1=value3&field2=value2')
58+
t.strictSame(payload, 'field1=value1&field1=value3&field2=value2')
5959
})
60-
t.deepEquals(form.headers, { 'content-type': 'application/x-www-form-urlencoded' })
60+
t.strictSame(form.headers, { 'content-type': 'application/x-www-form-urlencoded' })
6161
})
6262

6363
test('multipart/form-data', t => {
@@ -73,10 +73,10 @@ test('multipart/form-data', t => {
7373
const form = new multiparty.Form()
7474
form.parse(req, function (err, fields, files) {
7575
t.error(err)
76-
t.equals(fields.field1[0], '👌')
77-
t.equals(fields.field1[1], 'value1')
78-
t.equals(files.field2[0].originalFilename, 'LICENSE')
79-
t.equals(fields.field3[0], 'true')
76+
t.equal(fields.field1[0], '👌')
77+
t.equal(fields.field1[1], 'value1')
78+
t.equal(files.field2[0].originalFilename, 'LICENSE')
79+
t.equal(fields.field3[0], 'true')
8080
res.writeHead(200, { 'content-type': req.headers['content-type'] })
8181
res.end('')
8282
})
@@ -104,9 +104,9 @@ test('multipart/form-data multiple file', t => {
104104
const form = new multiparty.Form()
105105
form.parse(req, function (err, fields, files) {
106106
t.error(err)
107-
t.equals(fields.field1[0], 'a string')
108-
t.equals(files.field1[0].originalFilename, 'LICENSE')
109-
t.equals(files.field1[1].originalFilename, 'LICENSE')
107+
t.equal(fields.field1[0], 'a string')
108+
t.equal(files.field1[0].originalFilename, 'LICENSE')
109+
t.equal(files.field1[1].originalFilename, 'LICENSE')
110110
res.writeHead(200, { 'content-type': req.headers['content-type'] })
111111
res.end('')
112112
})
@@ -146,14 +146,14 @@ test('multipart/form-data with options', t => {
146146
const form = new multiparty.Form()
147147
form.parse(req, function (err, fields, files) {
148148
t.error(err)
149-
t.equals(fields.field1[0], '👌')
150-
t.equals(fields.field1[1], 'value1')
151-
t.equals(fields.field4[0], 'a string')
152-
t.equals(files.field2[0].originalFilename, 'bar.md')
153-
t.equals(fs.readFileSync(files.field2[0].path, 'utf-8'), fs.readFileSync('./LICENSE', 'utf-8'))
154-
t.equals(fields.field3[0], 'true')
155-
t.equals(files.field4[0].originalFilename, 'LICENSE')
156-
t.equals(files.field4[1].originalFilename, 'suboption-in-array.md')
149+
t.equal(fields.field1[0], '👌')
150+
t.equal(fields.field1[1], 'value1')
151+
t.equal(fields.field4[0], 'a string')
152+
t.equal(files.field2[0].originalFilename, 'bar.md')
153+
t.equal(fs.readFileSync(files.field2[0].path, 'utf-8'), fs.readFileSync('./LICENSE', 'utf-8'))
154+
t.equal(fields.field3[0], 'true')
155+
t.equal(files.field4[0].originalFilename, 'LICENSE')
156+
t.equal(files.field4[1].originalFilename, 'suboption-in-array.md')
157157
res.writeHead(200, { 'content-type': req.headers['content-type'] })
158158
res.end('')
159159
})

0 commit comments

Comments
 (0)