Skip to content

Commit

Permalink
test: express integration
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Jul 22, 2015
1 parent 349a2d1 commit de02a70
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"xtend": "^4.0.0"
},
"devDependencies": {
"express": "^4.13.1",
"form-data": "^1.0.0-rc1",
"fs-temp": "^0.1.2",
"mocha": "^2.2.5",
Expand Down
53 changes: 53 additions & 0 deletions test/express-integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-env mocha */

var assert = require('assert')

var multer = require('../')
var util = require('./_util')

var express = require('express')
var FormData = require('form-data')
var concat = require('concat-stream')

var port = 34279

describe('Express Integration', function () {
it('should work with express error handling', function (done) {
var app = express()
var limits = { fileSize: 200 }
var upload = multer({ limits: limits })
var form = new FormData()

var routeCalled = 0
var errorCalled = 0

form.append('avatar', util.file('small1.dat'))

app.post('/profile', upload.single('avatar'), function (req, res, next) {
routeCalled++
res.status(200).end('')
})

app.use(function (err, req, res, next) {
assert.equal(err.code, 'LIMIT_FILE_SIZE')

errorCalled++
res.status(500).end('')
})

app.listen(port, function () {
form.submit('http://localhost:' + port + '/profile', function (err, res) {
assert.ifError(err)

res.pipe(concat({ encoding: 'buffer' }, function (body) {
assert.equal(routeCalled, 0)
assert.equal(errorCalled, 1)
assert.equal(body.length, 0)
assert.equal(res.statusCode, 500)

done()
}))
})
})
})
})

0 comments on commit de02a70

Please sign in to comment.