Skip to content

Commit

Permalink
package: bump standard
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Apr 24, 2020
1 parent 8a351de commit ca0bb81
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 225 deletions.
4 changes: 2 additions & 2 deletions lib/make-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function makeMiddleware (setup) {
if (valueTruncated) return abortWithCode('LIMIT_FIELD_VALUE', fieldname)

// Work around bug in Busboy (https://github.com/mscdex/busboy/issues/6)
if (limits && limits.hasOwnProperty('fieldNameSize')) {
if (limits && Object.prototype.hasOwnProperty.call(limits, 'fieldNameSize')) {
if (fieldname.length > limits.fieldNameSize) return abortWithCode('LIMIT_FIELD_KEY')
}

Expand All @@ -98,7 +98,7 @@ function makeMiddleware (setup) {
if (!filename) return fileStream.resume()

// Work around bug in Busboy (https://github.com/mscdex/busboy/issues/6)
if (limits && limits.hasOwnProperty('fieldNameSize')) {
if (limits && Object.prototype.hasOwnProperty.call(limits, 'fieldNameSize')) {
if (fieldname.length > limits.fieldNameSize) return abortWithCode('LIMIT_FIELD_KEY')
}

Expand Down
14 changes: 7 additions & 7 deletions lib/multer-error.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var util = require('util')

var errorMessages = {
'LIMIT_PART_COUNT': 'Too many parts',
'LIMIT_FILE_SIZE': 'File too large',
'LIMIT_FILE_COUNT': 'Too many files',
'LIMIT_FIELD_KEY': 'Field name too long',
'LIMIT_FIELD_VALUE': 'Field value too long',
'LIMIT_FIELD_COUNT': 'Too many fields',
'LIMIT_UNEXPECTED_FILE': 'Unexpected field'
LIMIT_PART_COUNT: 'Too many parts',
LIMIT_FILE_SIZE: 'File too large',
LIMIT_FILE_COUNT: 'Too many files',
LIMIT_FIELD_KEY: 'Field name too long',
LIMIT_FIELD_VALUE: 'Field value too long',
LIMIT_FIELD_COUNT: 'Too many fields',
LIMIT_UNEXPECTED_FILE: 'Unexpected field'
}

function MulterError (code, field) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
"xtend": "^4.0.0"
},
"devDependencies": {
"deep-equal": "^2.0.3",
"express": "^4.13.1",
"form-data": "^1.0.0-rc1",
"fs-temp": "^1.1.2",
"mocha": "^3.5.3",
"rimraf": "^2.4.1",
"standard": "^11.0.1",
"standard": "^14.3.3",
"testdata-w3c-json-form": "^1.0.0"
},
"engines": {
Expand Down
101 changes: 51 additions & 50 deletions test/disk-storage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */

var assert = require('assert')
var deepEqual = require('deep-equal')

var fs = require('fs')
var path = require('path')
Expand Down Expand Up @@ -37,12 +38,12 @@ describe('Disk Storage', function () {
util.submitForm(parser, form, function (err, req) {
assert.ifError(err)

assert.equal(req.body.name, 'Multer')
assert.strictEqual(req.body.name, 'Multer')

assert.equal(req.file.fieldname, 'small0')
assert.equal(req.file.originalname, 'small0.dat')
assert.equal(req.file.size, 1778)
assert.equal(util.fileSize(req.file.path), 1778)
assert.strictEqual(req.file.fieldname, 'small0')
assert.strictEqual(req.file.originalname, 'small0.dat')
assert.strictEqual(req.file.size, 1778)
assert.strictEqual(util.fileSize(req.file.path), 1778)

done()
})
Expand All @@ -66,18 +67,18 @@ describe('Disk Storage', function () {
util.submitForm(parser, form, function (err, req) {
assert.ifError(err)

assert.equal(req.body.name, 'Multer')
assert.equal(req.body.version, '')
assert.equal(req.body.year, '')
assert.strictEqual(req.body.name, 'Multer')
assert.strictEqual(req.body.version, '')
assert.strictEqual(req.body.year, '')

assert.deepEqual(req.body.checkboxfull, [ 'cb1', 'cb2' ])
assert.deepEqual(req.body.checkboxhalfempty, [ 'cb1', '' ])
assert.deepEqual(req.body.checkboxempty, [ '', '' ])
assert(deepEqual(req.body.checkboxfull, ['cb1', 'cb2']))
assert(deepEqual(req.body.checkboxhalfempty, ['cb1', '']))
assert(deepEqual(req.body.checkboxempty, ['', '']))

assert.equal(req.file.fieldname, 'empty')
assert.equal(req.file.originalname, 'empty.dat')
assert.equal(req.file.size, 0)
assert.equal(util.fileSize(req.file.path), 0)
assert.strictEqual(req.file.fieldname, 'empty')
assert.strictEqual(req.file.originalname, 'empty.dat')
assert.strictEqual(req.file.size, 0)
assert.strictEqual(util.fileSize(req.file.path), 0)

done()
})
Expand Down Expand Up @@ -106,42 +107,42 @@ describe('Disk Storage', function () {
util.submitForm(parser, form, function (err, req) {
assert.ifError(err)

assert.deepEqual(req.body, {})
assert(deepEqual(req.body, {}))

assert.equal(req.files['empty'][0].fieldname, 'empty')
assert.equal(req.files['empty'][0].originalname, 'empty.dat')
assert.equal(req.files['empty'][0].size, 0)
assert.equal(util.fileSize(req.files['empty'][0].path), 0)
assert.strictEqual(req.files.empty[0].fieldname, 'empty')
assert.strictEqual(req.files.empty[0].originalname, 'empty.dat')
assert.strictEqual(req.files.empty[0].size, 0)
assert.strictEqual(util.fileSize(req.files.empty[0].path), 0)

assert.equal(req.files['tiny0'][0].fieldname, 'tiny0')
assert.equal(req.files['tiny0'][0].originalname, 'tiny0.dat')
assert.equal(req.files['tiny0'][0].size, 122)
assert.equal(util.fileSize(req.files['tiny0'][0].path), 122)
assert.strictEqual(req.files.tiny0[0].fieldname, 'tiny0')
assert.strictEqual(req.files.tiny0[0].originalname, 'tiny0.dat')
assert.strictEqual(req.files.tiny0[0].size, 122)
assert.strictEqual(util.fileSize(req.files.tiny0[0].path), 122)

assert.equal(req.files['tiny1'][0].fieldname, 'tiny1')
assert.equal(req.files['tiny1'][0].originalname, 'tiny1.dat')
assert.equal(req.files['tiny1'][0].size, 7)
assert.equal(util.fileSize(req.files['tiny1'][0].path), 7)
assert.strictEqual(req.files.tiny1[0].fieldname, 'tiny1')
assert.strictEqual(req.files.tiny1[0].originalname, 'tiny1.dat')
assert.strictEqual(req.files.tiny1[0].size, 7)
assert.strictEqual(util.fileSize(req.files.tiny1[0].path), 7)

assert.equal(req.files['small0'][0].fieldname, 'small0')
assert.equal(req.files['small0'][0].originalname, 'small0.dat')
assert.equal(req.files['small0'][0].size, 1778)
assert.equal(util.fileSize(req.files['small0'][0].path), 1778)
assert.strictEqual(req.files.small0[0].fieldname, 'small0')
assert.strictEqual(req.files.small0[0].originalname, 'small0.dat')
assert.strictEqual(req.files.small0[0].size, 1778)
assert.strictEqual(util.fileSize(req.files.small0[0].path), 1778)

assert.equal(req.files['small1'][0].fieldname, 'small1')
assert.equal(req.files['small1'][0].originalname, 'small1.dat')
assert.equal(req.files['small1'][0].size, 315)
assert.equal(util.fileSize(req.files['small1'][0].path), 315)
assert.strictEqual(req.files.small1[0].fieldname, 'small1')
assert.strictEqual(req.files.small1[0].originalname, 'small1.dat')
assert.strictEqual(req.files.small1[0].size, 315)
assert.strictEqual(util.fileSize(req.files.small1[0].path), 315)

assert.equal(req.files['medium'][0].fieldname, 'medium')
assert.equal(req.files['medium'][0].originalname, 'medium.dat')
assert.equal(req.files['medium'][0].size, 13196)
assert.equal(util.fileSize(req.files['medium'][0].path), 13196)
assert.strictEqual(req.files.medium[0].fieldname, 'medium')
assert.strictEqual(req.files.medium[0].originalname, 'medium.dat')
assert.strictEqual(req.files.medium[0].size, 13196)
assert.strictEqual(util.fileSize(req.files.medium[0].path), 13196)

assert.equal(req.files['large'][0].fieldname, 'large')
assert.equal(req.files['large'][0].originalname, 'large.jpg')
assert.equal(req.files['large'][0].size, 2413677)
assert.equal(util.fileSize(req.files['large'][0].path), 2413677)
assert.strictEqual(req.files.large[0].fieldname, 'large')
assert.strictEqual(req.files.large[0].originalname, 'large.jpg')
assert.strictEqual(req.files.large[0].size, 2413677)
assert.strictEqual(util.fileSize(req.files.large[0].path), 2413677)

done()
})
Expand All @@ -155,12 +156,12 @@ describe('Disk Storage', function () {
form.append('small0', util.file('small0.dat'))

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_UNEXPECTED_FILE')
assert.equal(err.field, 'small0')
assert.deepEqual(err.storageErrors, [])
assert.strictEqual(err.code, 'LIMIT_UNEXPECTED_FILE')
assert.strictEqual(err.field, 'small0')
assert(deepEqual(err.storageErrors, []))

var files = fs.readdirSync(uploadDir)
assert.deepEqual(files, [])
assert(deepEqual(files, []))

done()
})
Expand All @@ -178,8 +179,8 @@ describe('Disk Storage', function () {
form.append('tiny0', util.file('tiny0.dat'))

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'ENOENT')
assert.equal(path.dirname(err.path), directory)
assert.strictEqual(err.code, 'ENOENT')
assert.strictEqual(path.dirname(err.path), directory)

done()
})
Expand Down
46 changes: 23 additions & 23 deletions test/error-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ describe('Error Handling', function () {
it('should be an instance of both `Error` and `MulterError` classes in case of the Multer\'s error', function (done) {
var form = new FormData()
var storage = multer.diskStorage({ destination: os.tmpdir() })
var upload = multer({storage: storage}).fields([
var upload = multer({ storage: storage }).fields([
{ name: 'small0', maxCount: 1 }
])

form.append('small0', util.file('small0.dat'))
form.append('small0', util.file('small0.dat'))

util.submitForm(upload, form, function (err, req) {
assert.equal(err instanceof Error, true)
assert.equal(err instanceof multer.MulterError, true)
assert.strictEqual(err instanceof Error, true)
assert.strictEqual(err instanceof multer.MulterError, true)
done()
})
})
Expand All @@ -41,7 +41,7 @@ describe('Error Handling', function () {
form.append('small0', util.file('small0.dat'))

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_PART_COUNT')
assert.strictEqual(err.code, 'LIMIT_PART_COUNT')
done()
})
})
Expand All @@ -57,8 +57,8 @@ describe('Error Handling', function () {
form.append('small0', util.file('small0.dat'))

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_FILE_SIZE')
assert.equal(err.field, 'small0')
assert.strictEqual(err.code, 'LIMIT_FILE_SIZE')
assert.strictEqual(err.field, 'small0')
done()
})
})
Expand All @@ -74,7 +74,7 @@ describe('Error Handling', function () {
form.append('small1', util.file('small1.dat'))

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_FILE_COUNT')
assert.strictEqual(err.code, 'LIMIT_FILE_COUNT')
done()
})
})
Expand All @@ -88,7 +88,7 @@ describe('Error Handling', function () {
form.append('small0', util.file('small0.dat'))

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_FIELD_KEY')
assert.strictEqual(err.code, 'LIMIT_FIELD_KEY')
done()
})
})
Expand All @@ -101,7 +101,7 @@ describe('Error Handling', function () {
form.append('blowup', 'BOOM!')

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_FIELD_KEY')
assert.strictEqual(err.code, 'LIMIT_FIELD_KEY')
done()
})
})
Expand All @@ -114,8 +114,8 @@ describe('Error Handling', function () {
form.append('field1', 'This will make the parser explode')

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_FIELD_VALUE')
assert.equal(err.field, 'field1')
assert.strictEqual(err.code, 'LIMIT_FIELD_VALUE')
assert.strictEqual(err.field, 'field1')
done()
})
})
Expand All @@ -128,7 +128,7 @@ describe('Error Handling', function () {
form.append('field1', 'BOOM!')

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_FIELD_COUNT')
assert.strictEqual(err.code, 'LIMIT_FIELD_COUNT')
done()
})
})
Expand All @@ -142,8 +142,8 @@ describe('Error Handling', function () {
form.append('small0', util.file('small0.dat'))

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_UNEXPECTED_FILE')
assert.equal(err.field, 'small0')
assert.strictEqual(err.code, 'LIMIT_UNEXPECTED_FILE')
assert.strictEqual(err.field, 'small0')
done()
})
})
Expand All @@ -165,13 +165,13 @@ describe('Error Handling', function () {
form.append('small0', util.file('small0.dat'))

util.submitForm(parser, form, function (err, req) {
assert.equal(err.code, 'LIMIT_UNEXPECTED_FILE')
assert.equal(err.field, 'small0')
assert.strictEqual(err.code, 'LIMIT_UNEXPECTED_FILE')
assert.strictEqual(err.field, 'small0')

assert.equal(err.storageErrors.length, 1)
assert.equal(err.storageErrors[0].code, 'TEST')
assert.equal(err.storageErrors[0].field, 'tiny0')
assert.equal(err.storageErrors[0].file, req.file)
assert.strictEqual(err.storageErrors.length, 1)
assert.strictEqual(err.storageErrors[0].code, 'TEST')
assert.strictEqual(err.storageErrors[0].field, 'tiny0')
assert.strictEqual(err.storageErrors[0].file, req.file)

done()
})
Expand All @@ -191,7 +191,7 @@ describe('Error Handling', function () {
req.end(body)

upload(req, null, function (err) {
assert.equal(err.message, 'Multipart: Boundary not found')
assert.strictEqual(err.message, 'Multipart: Boundary not found')
done()
})
})
Expand All @@ -217,7 +217,7 @@ describe('Error Handling', function () {
req.end(body)

upload(req, null, function (err) {
assert.equal(err.message, 'Unexpected end of multipart data')
assert.strictEqual(err.message, 'Unexpected end of multipart data')
done()
})
})
Expand All @@ -233,7 +233,7 @@ describe('Error Handling', function () {
form.append('small0', util.file('small0.dat'))

util.submitForm(upload, form, function (err, req) {
assert.equal(err.code, 'LIMIT_FILE_SIZE')
assert.strictEqual(err.code, 'LIMIT_FILE_SIZE')
done()
})
})
Expand Down
Loading

0 comments on commit ca0bb81

Please sign in to comment.