@fastify/multipart
Advanced tools
Comparing version 7.4.1 to 7.4.2
@@ -527,2 +527,6 @@ 'use strict' | ||
if (attachFieldsToBody === true) { | ||
// Skip the whole process if the body is empty | ||
if (!this.body) { | ||
return [] | ||
} | ||
files = filesFromFields.call(this, this.body) | ||
@@ -529,0 +533,0 @@ } else { |
{ | ||
"name": "@fastify/multipart", | ||
"version": "7.4.1", | ||
"version": "7.4.2", | ||
"description": "Multipart plugin for Fastify", | ||
@@ -38,3 +38,3 @@ "main": "index.js", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.25.0" | ||
"tsd": "^0.26.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "scripts": { |
@@ -118,3 +118,3 @@ 'use strict' | ||
fastify.post('/', async function (req, reply) { | ||
t.ok(req.isMultipart()) | ||
t.ok(req.isMultipart(), 'is multipart') | ||
@@ -126,2 +126,3 @@ const part = await req.file() | ||
await part.toBuffer() | ||
reply.send('not ok') | ||
t.fail('it should throw') | ||
@@ -132,2 +133,3 @@ } catch (error) { | ||
} | ||
return reply | ||
}) | ||
@@ -157,3 +159,3 @@ | ||
const [res] = await once(req, 'response') | ||
t.equal(res.statusCode, 413) | ||
t.equal(res.statusCode, 413, 'status code equal') | ||
res.resume() | ||
@@ -160,0 +162,0 @@ await once(res, 'end') |
@@ -261,4 +261,2 @@ 'use strict' | ||
test('should throw error due to filesLimit (The max number of file fields (Default: Infinity))', function (t) { | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -273,3 +271,3 @@ t.teardown(fastify.close.bind(fastify)) | ||
for await (const part of parts) { | ||
t.ok(part.file) | ||
t.ok(part.file, 'part received') | ||
await sendToWormhole(part.file) | ||
@@ -279,3 +277,3 @@ } | ||
} catch (error) { | ||
t.ok(error instanceof fastify.multipartErrors.FilesLimitError) | ||
t.ok(error instanceof fastify.multipartErrors.FilesLimitError, 'error') | ||
reply.code(500).send() | ||
@@ -297,7 +295,13 @@ } | ||
let ended = false | ||
const req = http.request(opts, (res) => { | ||
t.equal(res.statusCode, 500) | ||
t.equal(res.statusCode, 500, 'status code') | ||
res.resume() | ||
res.on('end', () => { | ||
if (ended) { | ||
return | ||
} | ||
ended = true | ||
t.pass('res ended successfully') | ||
t.end() | ||
}) | ||
@@ -308,2 +312,10 @@ }) | ||
form.pipe(req) | ||
req.on('error', (err) => { | ||
if (ended) { | ||
return | ||
} | ||
ended = true | ||
t.equal(err.code, 'ECONNRESET') | ||
t.end() | ||
}) | ||
}) | ||
@@ -313,4 +325,2 @@ }) | ||
test('should be able to configure limits globally with plugin register options', function (t) { | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -335,3 +345,3 @@ t.teardown(fastify.close.bind(fastify)) | ||
fastify.listen({ port: 0 }, async function () { | ||
fastify.listen({ port: 0 }, function () { | ||
// request | ||
@@ -348,2 +358,3 @@ const form = new FormData() | ||
let ended = false | ||
const req = http.request(opts, (res) => { | ||
@@ -353,3 +364,8 @@ t.equal(res.statusCode, 500) | ||
res.on('end', () => { | ||
if (ended) { | ||
return | ||
} | ||
ended = true | ||
t.pass('res ended successfully') | ||
t.end() | ||
}) | ||
@@ -359,8 +375,12 @@ }) | ||
form.append('upload2', fs.createReadStream(filePath)) | ||
req.on('error', (err) => { | ||
if (ended) { | ||
return | ||
} | ||
ended = true | ||
t.equal(err.code, 'ECONNRESET') | ||
t.end() | ||
}) | ||
try { | ||
await pump(form, req) | ||
} catch (error) { | ||
t.error(error, 'formData request pump: no err') | ||
} | ||
pump(form, req).catch(() => {}) | ||
}) | ||
@@ -389,3 +409,3 @@ }) | ||
fastify.listen({ port: 0 }, async function () { | ||
fastify.listen({ port: 0 }, function () { | ||
// request | ||
@@ -392,0 +412,0 @@ const form = new FormData() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170261
37
4858
18