Skip to content

Commit 30222db

Browse files
committed
chore: drop deep-equal devDependency
According to deep-equal's own docs: > Node's assert.deepEqual() algorithm as a standalone module, that also works in browser environments. Since the tests are running in Node.js only, we don't need an external dependency.
1 parent 5c8407f commit 30222db

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"xtend": "^4.0.2"
3131
},
3232
"devDependencies": {
33-
"deep-equal": "^2.0.3",
3433
"express": "^4.21.2",
3534
"form-data": "^4.0.2",
3635
"fs-temp": "^1.2.1",

test/_util.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,21 @@ exports.submitForm = function submitForm (multer, form, cb) {
2727
})
2828
})
2929
}
30+
31+
exports.toNullProtoDeep = function toNullProtoDeep (value) {
32+
if (Array.isArray(value)) {
33+
return value.map(function (item) { return toNullProtoDeep(item) })
34+
}
35+
36+
if (value && typeof value === 'object') {
37+
var out = Object.create(null)
38+
39+
Object.keys(value).forEach(function (key) {
40+
out[key] = toNullProtoDeep(value[key])
41+
})
42+
43+
return out
44+
}
45+
46+
return value
47+
}

test/disk-storage.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-env mocha */
22

33
var assert = require('assert')
4-
var deepEqual = require('deep-equal')
54

65
var fs = require('fs')
76
var path = require('path')
@@ -71,9 +70,9 @@ describe('Disk Storage', function () {
7170
assert.strictEqual(req.body.version, '')
7271
assert.strictEqual(req.body.year, '')
7372

74-
assert(deepEqual(req.body.checkboxfull, ['cb1', 'cb2']))
75-
assert(deepEqual(req.body.checkboxhalfempty, ['cb1', '']))
76-
assert(deepEqual(req.body.checkboxempty, ['', '']))
73+
assert.deepStrictEqual(req.body.checkboxfull, ['cb1', 'cb2'])
74+
assert.deepStrictEqual(req.body.checkboxhalfempty, ['cb1', ''])
75+
assert.deepStrictEqual(req.body.checkboxempty, ['', ''])
7776

7877
assert.strictEqual(req.file.fieldname, 'empty')
7978
assert.strictEqual(req.file.originalname, 'empty.dat')
@@ -107,7 +106,7 @@ describe('Disk Storage', function () {
107106
util.submitForm(parser, form, function (err, req) {
108107
assert.ifError(err)
109108

110-
assert(deepEqual(req.body, {}))
109+
assert.deepStrictEqual(Object.assign({}, req.body), {})
111110

112111
assert.strictEqual(req.files.empty[0].fieldname, 'empty')
113112
assert.strictEqual(req.files.empty[0].originalname, 'empty.dat')
@@ -158,10 +157,10 @@ describe('Disk Storage', function () {
158157
util.submitForm(parser, form, function (err, req) {
159158
assert.strictEqual(err.code, 'LIMIT_UNEXPECTED_FILE')
160159
assert.strictEqual(err.field, 'small0')
161-
assert(deepEqual(err.storageErrors, []))
160+
assert.deepStrictEqual(err.storageErrors, [])
162161

163162
var files = fs.readdirSync(uploadDir)
164-
assert(deepEqual(files, []))
163+
assert.deepStrictEqual(files, [])
165164

166165
done()
167166
})

test/fields.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
/* eslint-env mocha */
22

33
var assert = require('assert')
4-
var deepEqual = require('deep-equal')
54
var stream = require('stream')
65

76
var util = require('./_util')
87
var multer = require('../')
98
var FormData = require('form-data')
10-
var testData = require('testdata-w3c-json-form')
9+
var rawTestData = require('testdata-w3c-json-form')
10+
11+
var testData = rawTestData.map(function (t) {
12+
return {
13+
name: t.name,
14+
fields: t.fields,
15+
expected: util.toNullProtoDeep(t.expected)
16+
}
17+
})
1118

1219
describe('Fields', function () {
1320
var parser
@@ -25,11 +32,11 @@ describe('Fields', function () {
2532

2633
util.submitForm(parser, form, function (err, req) {
2734
assert.ifError(err)
28-
assert(deepEqual(req.body, {
35+
assert.deepStrictEqual(Object.assign({}, req.body), {
2936
name: 'Multer',
3037
key: 'value',
3138
abc: 'xyz'
32-
}))
39+
})
3340
done()
3441
})
3542
})
@@ -49,14 +56,14 @@ describe('Fields', function () {
4956

5057
util.submitForm(parser, form, function (err, req) {
5158
assert.ifError(err)
52-
assert(deepEqual(req.body, {
59+
assert.deepStrictEqual(Object.assign({}, req.body), {
5360
name: 'Multer',
5461
key: '',
5562
abc: '',
5663
checkboxfull: ['cb1', 'cb2'],
5764
checkboxhalfempty: ['cb1', ''],
5865
checkboxempty: ['', '']
59-
}))
66+
})
6067
done()
6168
})
6269
})
@@ -107,7 +114,7 @@ describe('Fields', function () {
107114

108115
util.submitForm(parser, form, function (err, req) {
109116
assert.ifError(err)
110-
assert(deepEqual(req.body, test.expected))
117+
assert.deepStrictEqual(req.body, test.expected)
111118
done()
112119
})
113120
})
@@ -122,7 +129,7 @@ describe('Fields', function () {
122129

123130
util.submitForm(parser, form, function (err, req) {
124131
assert.ifError(err)
125-
assert(deepEqual(req.body, {
132+
assert.deepStrictEqual(req.body, util.toNullProtoDeep({
126133
obj: {
127134
0: 'a',
128135
2: 'c',

test/memory-storage.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-env mocha */
22

33
var assert = require('assert')
4-
var deepEqual = require('deep-equal')
54

65
var util = require('./_util')
76
var multer = require('../')
@@ -58,9 +57,9 @@ describe('Memory Storage', function () {
5857
assert.strictEqual(req.body.version, '')
5958
assert.strictEqual(req.body.year, '')
6059

61-
assert(deepEqual(req.body.checkboxfull, ['cb1', 'cb2']))
62-
assert(deepEqual(req.body.checkboxhalfempty, ['cb1', '']))
63-
assert(deepEqual(req.body.checkboxempty, ['', '']))
60+
assert.deepStrictEqual(req.body.checkboxfull, ['cb1', 'cb2'])
61+
assert.deepStrictEqual(req.body.checkboxhalfempty, ['cb1', ''])
62+
assert.deepStrictEqual(req.body.checkboxempty, ['', ''])
6463

6564
assert.strictEqual(req.file.fieldname, 'empty')
6665
assert.strictEqual(req.file.originalname, 'empty.dat')
@@ -95,7 +94,7 @@ describe('Memory Storage', function () {
9594
util.submitForm(parser, form, function (err, req) {
9695
assert.ifError(err)
9796

98-
assert(deepEqual(req.body, {}))
97+
assert.deepStrictEqual(Object.assign({}, req.body), {})
9998

10099
assert.strictEqual(req.files.empty[0].fieldname, 'empty')
101100
assert.strictEqual(req.files.empty[0].originalname, 'empty.dat')

0 commit comments

Comments
 (0)