create-test-server
Advanced tools
Comparing version 2.3.1 to 2.4.0
{ | ||
"name": "create-test-server", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"description": "Creates a minimal Express server for testing", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -167,2 +167,9 @@ # create-test-server | ||
##### options.bodyParser | ||
Type: `object` | ||
Default: `undefined` | ||
Body parser options to be passed to [`body-parser`](https://github.com/expressjs/body-parser) methods. | ||
### server | ||
@@ -169,0 +176,0 @@ |
@@ -27,7 +27,6 @@ 'use strict'; | ||
app.set('etag', false); | ||
app.use(bodyParser.json({ type: 'application/json' })); | ||
app.use(bodyParser.text({ type: 'text/plain' })); | ||
app.use(bodyParser.urlencoded({ type: 'application/x-www-form-urlencoded', extended: true })); | ||
app.use(bodyParser.raw({ type: 'application/octet-stream' })); | ||
app.use(bodyParser.json(Object.assign({ limit: '1mb', type: 'application/json' }, opts && opts.bodyParser))); | ||
app.use(bodyParser.text(Object.assign({ limit: '1mb', type: 'text/plain' }, opts && opts.bodyParser))); | ||
app.use(bodyParser.urlencoded(Object.assign({ limit: '1mb', type: 'application/x-www-form-urlencoded', extended: true }, opts && opts.bodyParser))); | ||
app.use(bodyParser.raw(Object.assign({ limit: '1mb', type: 'application/octet-stream' }, opts && opts.bodyParser))); | ||
app.caCert = keys.caCert; | ||
@@ -34,0 +33,0 @@ |
@@ -156,2 +156,35 @@ import querystring from 'querystring'; | ||
test('opts.bodyParser is passed through to bodyParser', async t => { | ||
const smallServer = await createTestServer({ bodyParser: { limit: '100kb' } }); | ||
const bigServer = await createTestServer({ bodyParser: { limit: '200kb' } }); | ||
const buf = Buffer.alloc(150 * 1024); | ||
// Custom error handler so we don't dump the stack trace in the test output | ||
smallServer.use((err, req, res, next) => { // eslint-disable-line no-unused-vars | ||
res.status(500).end(); | ||
}); | ||
t.plan(3); | ||
smallServer.post('/', (req, res) => { | ||
t.fail(); | ||
res.end(); | ||
}); | ||
bigServer.post('/', (req, res) => { | ||
t.true(req.body.length === buf.length); | ||
res.end(); | ||
}); | ||
await t.throws(got.post(smallServer.url, { | ||
headers: { 'content-type': 'application/octet-stream' }, | ||
body: buf | ||
})); | ||
await t.notThrows(got.post(bigServer.url, { | ||
headers: { 'content-type': 'application/octet-stream' }, | ||
body: buf | ||
})); | ||
}); | ||
test('support returning body directly', async t => { | ||
@@ -158,0 +191,0 @@ const server = await createTestServer(); |
17049
237
251