forked from expressjs/multer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reuse-middleware.js
57 lines (44 loc) · 1.3 KB
/
reuse-middleware.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint-env mocha */
var assert = require('assert')
var util = require('./_util')
var multer = require('../')
var FormData = require('form-data')
describe('Reuse Middleware', function () {
var parser
before(function (done) {
parser = multer().array('them-files')
done()
})
it('should accept multiple requests', function (done) {
var pending = 8
function submitData (fileCount) {
var form = new FormData()
form.append('name', 'Multer')
form.append('files', '' + fileCount)
for (var i = 0; i < fileCount; i++) {
form.append('them-files', util.file('small0.dat'))
}
util.submitForm(parser, form, function (err, req) {
assert.ifError(err)
assert.equal(req.body.name, 'Multer')
assert.equal(req.body.files, '' + fileCount)
assert.equal(req.files.length, fileCount)
req.files.forEach(function (file) {
assert.equal(file.fieldname, 'them-files')
assert.equal(file.originalname, 'small0.dat')
assert.equal(file.size, 1778)
assert.equal(file.buffer.length, 1778)
})
if (--pending === 0) done()
})
}
submitData(9)
submitData(1)
submitData(5)
submitData(7)
submitData(2)
submitData(8)
submitData(3)
submitData(4)
})
})