@fastify/multipart
Advanced tools
| import fastifyMultipart, { | ||
| type MultipartFile, | ||
| type MultipartValue, | ||
| } from '@fastify/multipart' | ||
| import fastify from 'fastify' | ||
| import { | ||
| serializerCompiler, | ||
| validatorCompiler, | ||
| type ZodTypeProvider, | ||
| } from 'fastify-type-provider-zod' | ||
| import { z } from 'zod' | ||
| const app = fastify().withTypeProvider<ZodTypeProvider>() | ||
| app.setSerializerCompiler(serializerCompiler) | ||
| app.setValidatorCompiler(validatorCompiler) | ||
| app.register(fastifyMultipart, { attachFieldsToBody: true }) | ||
| // You can use attachFieldsToBody: "keyValues" to avoid another fields preprocessing, but in that case, you will receive a Buffer for files that are not text/plain. | ||
| app.post( | ||
| '/upload', | ||
| { | ||
| schema: { | ||
| consumes: ['multipart/form-data'], | ||
| body: z.object({ | ||
| image: z | ||
| .custom<MultipartFile>() | ||
| .refine((file) => file?.file, { | ||
| message: 'The image is required.', | ||
| }) | ||
| .refine((file) => !file || file.file?.bytesRead <= 10 * 1024 * 1024, { | ||
| message: 'The image must be a maximum of 10MB.', | ||
| }) | ||
| .refine((file) => !file || file.mimetype.startsWith('image'), { | ||
| message: 'Only images are allowed to be sent.', | ||
| }), | ||
| anotherField: z.preprocess( | ||
| (file) => (file as MultipartValue).value, | ||
| z.string() /* validation here */ | ||
| ), | ||
| /* another fields here */ | ||
| }), | ||
| }, | ||
| }, | ||
| async (request, reply) => { | ||
| const { image, anotherField } = request.body | ||
| console.log('imageType:', image.mimetype) | ||
| console.log('anotherField:', anotherField) | ||
| return reply.send('OK') | ||
| } | ||
| ) | ||
| app.listen({ port: 8000 }, (err, address) => { | ||
| if (err) { | ||
| console.error(err) | ||
| process.exit(1) | ||
| } | ||
| console.log(`Server listening at ${address}`) | ||
| }) |
@@ -7,3 +7,2 @@ name: CI | ||
| - main | ||
| - master | ||
| - next | ||
@@ -19,4 +18,10 @@ - 'v*' | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| test: | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5 | ||
@@ -23,0 +28,0 @@ with: |
+3
-1
| MIT License | ||
| Copyright (c) 2017 Fastify | ||
| Copyright (c) 2017-present The Fastify team | ||
| The Fastify team members are listed at https://github.com/fastify/fastify#team. | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
@@ -6,0 +8,0 @@ of this software and associated documentation files (the "Software"), to deal |
+7
-8
| { | ||
| "name": "@fastify/multipart", | ||
| "version": "9.1.0", | ||
| "version": "9.2.0", | ||
| "description": "Multipart plugin for Fastify", | ||
@@ -10,6 +10,7 @@ "main": "index.js", | ||
| "@fastify/busboy": "^3.0.0", | ||
| "@fastify/deepmerge": "^2.0.0", | ||
| "@fastify/deepmerge": "^3.0.0", | ||
| "@fastify/error": "^4.0.0", | ||
| "c8": "^10.1.3", | ||
| "fastify-plugin": "^5.0.0", | ||
| "secure-json-parse": "^3.0.0" | ||
| "secure-json-parse": "^4.0.0" | ||
| }, | ||
@@ -20,3 +21,3 @@ "devDependencies": { | ||
| "@fastify/swagger-ui": "^5.0.0", | ||
| "@types/node": "^22.0.0", | ||
| "@types/node": "^24.0.8", | ||
| "benchmark": "^2.1.4", | ||
@@ -33,7 +34,5 @@ "climem": "^2.0.0", | ||
| "readable-stream": "^4.5.2", | ||
| "tap": "^18.6.1", | ||
| "tsd": "^0.31.0" | ||
| "tsd": "^0.33.0" | ||
| }, | ||
| "scripts": { | ||
| "coverage": "npm run test:unit -- --coverage-report=html", | ||
| "climem": "climem 8999 localhost", | ||
@@ -45,3 +44,3 @@ "lint": "eslint", | ||
| "test:typescript": "tsd", | ||
| "test:unit": "tap -t 120" | ||
| "test:unit": "c8 --100 node --test" | ||
| }, | ||
@@ -48,0 +47,0 @@ "repository": { |
+13
-1
| # @fastify/multipart | ||
| [](https://github.com/fastify/fastify-multipart/actions/workflows/ci.yml) | ||
| [](https://github.com/fastify/fastify-multipart/actions/workflows/ci.yml) | ||
| [](https://www.npmjs.com/package/@fastify/multipart) | ||
@@ -508,2 +508,14 @@ [](https://github.com/neostandard/neostandard) | ||
| ## Zod Schema body validation | ||
| To validate requests using [Zod](https://github.com/colinhacks/zod), you need to: | ||
| 1. Install and configure [`fastify-type-provider-zod`](https://github.com/turkerdev/fastify-type-provider-zod). | ||
| 1. Make sure the `attachFieldsToBody` option is set to `true` when registering the `@fastify/multipart` plugin. | ||
| 1. You can use `attachFieldsToBody: "keyValues"` to avoid another fields preprocessing, but in that case, you will receive a Buffer for files that are not text/plain. | ||
| After setup, you can validate your request body using a Zod schema as usual. | ||
| See a full example in [`examples/example-with-zod.ts`](examples/example-with-zod.ts). | ||
| ## Access all errors | ||
@@ -510,0 +522,0 @@ |
+22
-16
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -15,3 +15,3 @@ const Fastify = require('fastify') | ||
| // skipping on Github Actions because it takes too long | ||
| test('should upload a big file in constant memory', { skip: process.env.CI }, function (t) { | ||
| test('should upload a big file in constant memory', { skip: process.env.CI }, function (t, done) { | ||
| t.plan(10) | ||
@@ -22,3 +22,3 @@ | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -33,11 +33,11 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| for await (const part of req.parts()) { | ||
| if (part.file) { | ||
| t.equal(part.type, 'file') | ||
| t.equal(part.fieldname, 'upload') | ||
| t.equal(part.filename, 'random-data') | ||
| t.equal(part.encoding, '7bit') | ||
| t.equal(part.mimetype, 'binary/octet-stream') | ||
| t.assert.strictEqual(part.type, 'file') | ||
| t.assert.strictEqual(part.fieldname, 'upload') | ||
| t.assert.strictEqual(part.filename, 'random-data') | ||
| t.assert.strictEqual(part.encoding, '7bit') | ||
| t.assert.strictEqual(part.mimetype, 'binary/octet-stream') | ||
@@ -49,4 +49,4 @@ await streamToNull(part.file) | ||
| const memory = process.memoryUsage() | ||
| t.ok(memory.rss < 500 * 1024 * 1024) | ||
| t.ok(memory.heapTotal < 500 * 1024 * 1024) | ||
| t.assert.ok(memory.rss < 500 * 1024 * 1024) | ||
| t.assert.ok(memory.heapTotal < 500 * 1024 * 1024) | ||
@@ -73,3 +73,3 @@ reply.send() | ||
| if (total === 0) { | ||
| t.pass('finished generating') | ||
| t.assert.ok('finished generating') | ||
| hashInput.end() | ||
@@ -96,10 +96,16 @@ this.push(null) | ||
| const req = http.request(opts, () => { fastify.close(noop) }) | ||
| const req = http.request(opts, (res) => { | ||
| res.on('data', () => {}) | ||
| res.on('end', () => { | ||
| fastify.close(() => { | ||
| done() | ||
| }) | ||
| }) | ||
| }) | ||
| pump(form, req, function (err) { | ||
| t.error(err, 'client pump: no err') | ||
| t.assert.ifError(err, 'client pump: no err') | ||
| }) | ||
| }) | ||
| }) | ||
| function noop () { } |
+31
-31
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -20,3 +20,3 @@ const Fastify = require('fastify') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -28,27 +28,27 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const files = await req.saveRequestFiles() | ||
| t.ok(files[0].filepath) | ||
| t.equal(files[0].type, 'file') | ||
| t.equal(files[0].fieldname, 'upload') | ||
| t.equal(files[0].filename, 'README.md') | ||
| t.equal(files[0].encoding, '7bit') | ||
| t.equal(files[0].mimetype, 'text/markdown') | ||
| t.ok(files[0].fields.upload) | ||
| t.ok(files[1].filepath) | ||
| t.equal(files[1].type, 'file') | ||
| t.equal(files[1].fieldname, 'upload') | ||
| t.equal(files[1].filename, 'README.md') | ||
| t.equal(files[1].encoding, '7bit') | ||
| t.equal(files[1].mimetype, 'text/markdown') | ||
| t.ok(files[1].fields.upload) | ||
| t.ok(files[2].filepath) | ||
| t.equal(files[2].type, 'file') | ||
| t.equal(files[2].fieldname, 'other') | ||
| t.equal(files[2].filename, 'README.md') | ||
| t.equal(files[2].encoding, '7bit') | ||
| t.equal(files[2].mimetype, 'text/markdown') | ||
| t.ok(files[2].fields.upload) | ||
| t.assert.ok(files[0].filepath) | ||
| t.assert.strictEqual(files[0].type, 'file') | ||
| t.assert.strictEqual(files[0].fieldname, 'upload') | ||
| t.assert.strictEqual(files[0].filename, 'README.md') | ||
| t.assert.strictEqual(files[0].encoding, '7bit') | ||
| t.assert.strictEqual(files[0].mimetype, 'text/markdown') | ||
| t.assert.ok(files[0].fields.upload) | ||
| t.assert.ok(files[1].filepath) | ||
| t.assert.strictEqual(files[1].type, 'file') | ||
| t.assert.strictEqual(files[1].fieldname, 'upload') | ||
| t.assert.strictEqual(files[1].filename, 'README.md') | ||
| t.assert.strictEqual(files[1].encoding, '7bit') | ||
| t.assert.strictEqual(files[1].mimetype, 'text/markdown') | ||
| t.assert.ok(files[1].fields.upload) | ||
| t.assert.ok(files[2].filepath) | ||
| t.assert.strictEqual(files[2].type, 'file') | ||
| t.assert.strictEqual(files[2].fieldname, 'other') | ||
| t.assert.strictEqual(files[2].filename, 'README.md') | ||
| t.assert.strictEqual(files[2].encoding, '7bit') | ||
| t.assert.strictEqual(files[2].mimetype, 'text/markdown') | ||
| t.assert.ok(files[2].fields.upload) | ||
@@ -68,4 +68,4 @@ await access(files[0].filepath, fs.constants.F_OK) | ||
| } catch (error) { | ||
| t.equal(error.code, 'ENOENT') | ||
| t.pass('Temp file was removed after response') | ||
| t.assert.strictEqual(error.code, 'ENOENT') | ||
| t.assert.ok('Temp file was removed after response') | ||
| ee.emit('response') | ||
@@ -95,3 +95,3 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
@@ -106,3 +106,3 @@ await once(res, 'end') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -119,3 +119,3 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -126,3 +126,3 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.FileBufferNotFoundError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.FileBufferNotFoundError) | ||
| reply.code(500).send() | ||
@@ -150,5 +150,5 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| }) |
| 'use strict' | ||
| const { test } = require('tap') | ||
| const { test } = require('node:test') | ||
| const { generateId } = require('../lib/generateId') | ||
@@ -8,5 +8,5 @@ | ||
| t.plan(3) | ||
| t.type(generateId, 'function', 'is a function') | ||
| t.type(generateId(), 'string', '~> returns a string') | ||
| t.equal(generateId().length, 16, '~> has 16 characters (default)') | ||
| t.assert.strictEqual(typeof generateId, 'function', 'is a function') | ||
| t.assert.strictEqual(typeof generateId(), 'string', '~> returns a string') | ||
| t.assert.strictEqual(generateId().length, 16, '~> has 16 characters (default)') | ||
| }) | ||
@@ -22,3 +22,3 @@ | ||
| tmp = generateId() | ||
| t.equal(tmp.length, 16, `"${tmp}" is 16 characters`) | ||
| t.assert.strictEqual(tmp.length, 16, `"${tmp}" is 16 characters`) | ||
| } | ||
@@ -29,3 +29,3 @@ }) | ||
| t.plan(1) | ||
| t.not(generateId(), generateId(), '~> single') | ||
| t.assert.notStrictEqual(generateId(), generateId(), '~> single') | ||
| }) | ||
@@ -37,3 +37,3 @@ | ||
| for (let i = 5e6; i--;) items.add(generateId()) | ||
| t.equal(items.size, 5e6, '~> 5,000,000 unique ids') | ||
| t.assert.strictEqual(items.size, 5e6, '~> 5,000,000 unique ids') | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const Fastify = require('fastify') | ||
@@ -11,6 +10,7 @@ const FormData = require('form-data') | ||
| const path = require('node:path') | ||
| const test = require('node:test') | ||
| const filePath = path.join(__dirname, '../README.md') | ||
| test('show modify the generated schema', async function (t) { | ||
| test('show modify the generated schema', async t => { | ||
| t.plan(4) | ||
@@ -24,3 +24,3 @@ | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -36,3 +36,3 @@ await fastify.register(multipart, { attachFieldsToBody: true }) | ||
| await fastify.post( | ||
| fastify.post( | ||
| '/', | ||
@@ -58,22 +58,20 @@ { | ||
| t.match(fastify.swagger(), { | ||
| paths: { | ||
| '/': { | ||
| post: { | ||
| operationId: 'test', | ||
| requestBody: { | ||
| content: { | ||
| 'multipart/form-data': { | ||
| schema: { | ||
| type: 'object', | ||
| properties: { | ||
| field: { type: 'string', format: 'binary' } | ||
| } | ||
| t.assert.deepStrictEqual(fastify.swagger().paths, { | ||
| '/': { | ||
| post: { | ||
| operationId: 'test', | ||
| requestBody: { | ||
| content: { | ||
| 'multipart/form-data': { | ||
| schema: { | ||
| type: 'object', | ||
| properties: { | ||
| field: { type: 'string', format: 'binary' } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| responses: { | ||
| 200: { description: 'Default Response' } | ||
| } | ||
| }, | ||
| responses: { | ||
| 200: { description: 'Default Response' } | ||
| } | ||
@@ -104,3 +102,3 @@ } | ||
| await once(res, 'end') | ||
| t.equal(res.statusCode, 400) // body/field should be a file | ||
| t.assert.strictEqual(res.statusCode, 400) // body/field should be a file | ||
| } | ||
@@ -126,5 +124,5 @@ | ||
| await once(res, 'end') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| } | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -21,3 +21,3 @@ const Fastify = require('fastify') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -29,10 +29,9 @@ fastify.register(multipart, { attachFieldsToBody: true }) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['upload', 'hello']) | ||
| t.same(Object.keys(req.body), ['upload', 'hello']) | ||
| const content = await req.body.upload.toBuffer() | ||
| t.equal(content.toString(), original) | ||
| t.equal(req.body.hello.value, 'world') | ||
| t.assert.strictEqual(content.toString(), original) | ||
| t.assert.strictEqual(req.body.hello.value, 'world') | ||
@@ -61,6 +60,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -72,3 +71,3 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -80,8 +79,8 @@ fastify.register(multipart, { attachFieldsToBody: 'keyValues' }) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.same(Object.keys(req.body), ['upload', 'hello']) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['upload', 'hello']) | ||
| t.same(req.body.upload, original) | ||
| t.equal(req.body.hello, 'world') | ||
| t.assert.deepStrictEqual(req.body.upload, original) | ||
| t.assert.strictEqual(req.body.hello, 'world') | ||
@@ -110,6 +109,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -121,3 +120,3 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -129,10 +128,10 @@ fastify.register(multipart, { attachFieldsToBody: 'keyValues' }) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| req.body.upload = req.body.upload.toString('utf8') | ||
| t.same(Object.keys(req.body), ['upload', 'hello']) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['upload', 'hello']) | ||
| t.equal(req.body.upload, original) | ||
| t.equal(req.body.hello, 'world') | ||
| t.assert.strictEqual(req.body.upload, original) | ||
| t.assert.strictEqual(req.body.hello, 'world') | ||
@@ -161,6 +160,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -172,6 +171,6 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
| async function onFile (part) { | ||
| t.pass('custom onFile handler') | ||
| t.assert.ok('custom onFile handler') | ||
| const buff = await part.toBuffer() | ||
@@ -187,7 +186,7 @@ const decoded = Buffer.from(buff.toString(), 'base64').toString() | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.same(Object.keys(req.body), ['upload', 'hello']) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['upload', 'hello']) | ||
| t.equal(req.body.upload, original) | ||
| t.equal(req.body.hello, 'world') | ||
| t.assert.strictEqual(req.body.upload, original) | ||
| t.assert.strictEqual(req.body.hello, 'world') | ||
@@ -216,6 +215,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -227,6 +226,6 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
| async function onFile (part) { | ||
| t.pass('custom onFile handler') | ||
| t.assert.ok('custom onFile handler') | ||
| await part.toBuffer() | ||
@@ -240,10 +239,10 @@ } | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.same(Object.keys(req.body), ['upload', 'hello']) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['upload', 'hello']) | ||
| const content = await req.body.upload.toBuffer() | ||
| t.equal(content.toString(), original) | ||
| t.equal(req.body.hello.value, 'world') | ||
| t.assert.strictEqual(content.toString(), original) | ||
| t.assert.strictEqual(req.body.hello.value, 'world') | ||
@@ -272,13 +271,13 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
| test('should not process requests with content-type other than multipart', function (t) { | ||
| test('should not process requests with content-type other than multipart', function (t, done) { | ||
| t.plan(3) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -301,9 +300,10 @@ fastify.register(multipart, { attachFieldsToBody: true }) | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.on('data', function (data) { | ||
| t.equal(JSON.parse(data).hello, 'world') | ||
| t.assert.strictEqual(JSON.parse(data).hello, 'world') | ||
| }) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -319,3 +319,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -327,3 +327,3 @@ fastify.register(multipart, { attachFieldsToBody: 'keyValues' }) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -333,3 +333,3 @@ req.body.upload[0] = req.body.upload[0].toString('utf8') | ||
| t.same(req.body, { | ||
| t.assert.deepStrictEqual(req.body, { | ||
| upload: [original, original], | ||
@@ -363,6 +363,6 @@ hello: ['hello', 'world'] | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -374,8 +374,8 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
| async function onFile (part) { | ||
| t.pass('custom onFile handler') | ||
| t.equal(this.id, 'req-1') | ||
| t.equal(typeof this, 'object') | ||
| t.assert.ok('custom onFile handler') | ||
| t.assert.strictEqual(this.id, 'req-1') | ||
| t.assert.strictEqual(typeof this, 'object') | ||
| const buff = await part.toBuffer() | ||
@@ -391,3 +391,3 @@ const decoded = Buffer.from(buff.toString(), 'base64').toString() | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| reply.code(200).send() | ||
@@ -414,6 +414,6 @@ }) | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -425,7 +425,7 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
| async function onFile (part) { | ||
| pump(part.file, writableNoopStream()).once('end', () => { | ||
| t.pass('stream consumed successfully') | ||
| t.assert.ok('stream consumed successfully') | ||
| }) | ||
@@ -439,3 +439,3 @@ } | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| reply.code(200).send() | ||
@@ -462,6 +462,6 @@ }) | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -473,3 +473,3 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -481,9 +481,9 @@ fastify.register(multipart, { attachFieldsToBody: 'keyValues' }) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.same(Object.keys(req.body), ['upload', 'hello']) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['upload', 'hello']) | ||
| t.ok(req.body.upload instanceof Buffer) | ||
| t.ok(Buffer.compare(req.body.upload, original) === 0) | ||
| t.equal(req.body.hello, 'world') | ||
| t.assert.ok(req.body.upload instanceof Buffer) | ||
| t.assert.strictEqual(Buffer.compare(req.body.upload, original), 0) | ||
| t.assert.strictEqual(req.body.hello, 'world') | ||
@@ -512,6 +512,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -525,3 +525,3 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -533,14 +533,14 @@ fastify.register(multipart, { attachFieldsToBody: true }) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.same(Object.keys(req.body), ['upload', 'hello']) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['upload', 'hello']) | ||
| const formData = await req.formData() | ||
| t.equal(formData instanceof globalThis.FormData, true) | ||
| t.equal(formData.get('hello'), 'world') | ||
| t.same(formData.getAll('hello'), ['world', 'foo']) | ||
| t.equal(await formData.get('upload').text(), original) | ||
| t.equal(formData.get('upload').type, 'text/markdown') | ||
| t.equal(formData.get('upload').name, 'README.md') | ||
| t.assert.strictEqual(formData instanceof globalThis.FormData, true) | ||
| t.assert.strictEqual(formData.get('hello'), 'world') | ||
| t.assert.deepStrictEqual(formData.getAll('hello'), ['world', 'foo']) | ||
| t.assert.strictEqual(await formData.get('upload').text(), original) | ||
| t.assert.strictEqual(formData.get('upload').type, 'text/markdown') | ||
| t.assert.strictEqual(formData.get('upload').name, 'README.md') | ||
@@ -570,6 +570,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -18,3 +18,3 @@ const Fastify = require('fastify') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
| const hashInput = crypto.createHash('sha256') | ||
@@ -25,3 +25,3 @@ | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const part = await req.file({ limits: { fileSize: 16500 } }) | ||
@@ -55,3 +55,3 @@ await streamToNull(part.file) | ||
| if (total === 0) { | ||
| t.pass('finished generating') | ||
| t.assert.ok('finished generating') | ||
| hashInput.end() | ||
@@ -83,8 +83,8 @@ this.push(null) | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -13,7 +13,7 @@ const Fastify = require('fastify') | ||
| test('should be able to use JSON schema to validate request', function (t) { | ||
| test('should be able to use JSON schema to validate request', function (t, done) { | ||
| t.plan(7) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -36,11 +36,11 @@ fastify.register(multipart, { attachFieldsToBody: true, sharedSchemaId: '#mySharedSchema' }) | ||
| }, async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.same(Object.keys(req.body), ['upload', 'hello']) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['upload', 'hello']) | ||
| const content = await req.body.upload.toBuffer() | ||
| t.equal(content.toString(), original) | ||
| t.equal(req.body.hello.type, 'field') | ||
| t.equal(req.body.hello.value, 'world') | ||
| t.assert.strictEqual(content.toString(), original) | ||
| t.assert.strictEqual(req.body.hello.type, 'field') | ||
| t.assert.strictEqual(req.body.hello.value, 'world') | ||
@@ -63,6 +63,7 @@ reply.code(200).send() | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -76,7 +77,7 @@ }) | ||
| test('should throw because JSON schema is invalid', function (t) { | ||
| test('should throw because JSON schema is invalid', function (t, done) { | ||
| t.plan(2) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -121,6 +122,7 @@ fastify.register(multipart, { attachFieldsToBody: true, sharedSchemaId: '#mySharedSchema' }) | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 400) | ||
| t.assert.strictEqual(res.statusCode, 400) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -127,0 +129,0 @@ }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -13,7 +13,7 @@ const Fastify = require('fastify') | ||
| test('should be able to get whole buffer by accessing "content" on part', function (t) { | ||
| test('should be able to get whole buffer by accessing "content" on part', function (t, done) { | ||
| t.plan(4) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -25,3 +25,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -32,3 +32,3 @@ const file = await req.file() | ||
| t.equal(buf.toString(), original) | ||
| t.assert.strictEqual(buf.toString(), original) | ||
@@ -51,6 +51,7 @@ reply.code(200).send() | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -63,7 +64,7 @@ }) | ||
| test('should be able to access "content" multiple times without reading the stream twice', function (t) { | ||
| test('should be able to access "content" multiple times without reading the stream twice', function (t, done) { | ||
| t.plan(5) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -75,3 +76,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -83,4 +84,4 @@ const file = await req.file() | ||
| t.equal(buf.toString(), original) | ||
| t.equal(buf2.toString(), original) | ||
| t.assert.strictEqual(buf.toString(), original) | ||
| t.assert.strictEqual(buf2.toString(), original) | ||
@@ -103,6 +104,7 @@ reply.code(200).send() | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -109,0 +111,0 @@ }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -14,2 +14,3 @@ const Fastify = require('fastify') | ||
| const EventEmitter = require('node:events') | ||
| // const os = require('node:os') | ||
| const { once } = EventEmitter | ||
@@ -23,3 +24,3 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -29,12 +30,12 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const files = await req.saveRequestFiles() | ||
| t.ok(files[0].filepath) | ||
| t.equal(files[0].fieldname, 'upload') | ||
| t.equal(files[0].filename, 'README.md') | ||
| t.equal(files[0].encoding, '7bit') | ||
| t.equal(files[0].mimetype, 'text/markdown') | ||
| t.ok(files[0].fields.upload) | ||
| t.assert.ok(files[0].filepath) | ||
| t.assert.strictEqual(files[0].fieldname, 'upload') | ||
| t.assert.strictEqual(files[0].filename, 'README.md') | ||
| t.assert.strictEqual(files[0].encoding, '7bit') | ||
| t.assert.strictEqual(files[0].mimetype, 'text/markdown') | ||
| t.assert.ok(files[0].fields.upload) | ||
@@ -52,4 +53,4 @@ await access(files[0].filepath, fs.constants.F_OK) | ||
| } catch (error) { | ||
| t.equal(error.code, 'ENOENT') | ||
| t.pass('Temp file was removed after response') | ||
| t.assert.strictEqual(error.code, 'ENOENT') | ||
| t.assert.ok('Temp file was removed after response') | ||
| ee.emit('response') | ||
@@ -77,3 +78,3 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
@@ -88,3 +89,3 @@ await once(res, 'end') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -94,3 +95,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -109,4 +110,4 @@ await req.saveRequestFiles() | ||
| } catch (error) { | ||
| t.equal(error.code, 'ENOENT') | ||
| t.pass('Temp file was removed after response') | ||
| t.assert.strictEqual(error.code, 'ENOENT') | ||
| t.assert.ok('Temp file was removed after response') | ||
| ee.emit('response') | ||
@@ -129,6 +130,6 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -141,3 +142,3 @@ }) | ||
| } catch (error) { | ||
| t.error(error, 'formData request pump: no err') | ||
| t.assert.ifError(error, 'formData request pump: no err') | ||
| } | ||
@@ -151,3 +152,3 @@ await once(ee, 'response') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -157,3 +158,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -164,4 +165,4 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| t.equal(error.part.fieldname, 'upload') | ||
| t.assert.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| t.assert.strictEqual(error.part.fieldname, 'upload') | ||
| reply.code(500).send() | ||
@@ -189,7 +190,7 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -202,3 +203,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -208,3 +209,3 @@ fastify.register(require('..')) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -239,7 +240,7 @@ try { | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -252,10 +253,10 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
| fastify.register(require('..')) | ||
| const tmpdir = t.testdir() | ||
| const tmpdir = fs.mkdtempSync(path.join(__dirname, 'tmp')) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -265,3 +266,3 @@ try { | ||
| // temp file saved, remove before the onResponse hook | ||
| await fs.promises.rm(tmpdir, { recursive: true, force: true }) | ||
| fs.rmSync(tmpdir, { recursive: true, force: true }) | ||
| reply.code(200).send() | ||
@@ -293,7 +294,7 @@ } catch { | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -307,3 +308,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -313,3 +314,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -320,4 +321,4 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| t.equal(error.part.fieldname, 'upload2') | ||
| t.assert.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| t.assert.strictEqual(error.part.fieldname, 'upload2') | ||
| reply.code(500).send() | ||
@@ -346,3 +347,3 @@ } | ||
| if (total === 0) { | ||
| t.pass('finished generating') | ||
| t.assert.ok('finished generating') | ||
| hashInput.end() | ||
@@ -374,7 +375,7 @@ this.push(null) | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -387,3 +388,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -393,7 +394,7 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req) { | ||
| t.equal(req.tmpUploads, null) | ||
| t.assert.strictEqual(req.tmpUploads, null) | ||
| await req.saveRequestFiles() | ||
| t.equal(req.tmpUploads.length, 1) | ||
| t.assert.strictEqual(req.tmpUploads.length, 1) | ||
@@ -409,4 +410,4 @@ throw new Error('test') | ||
| } catch (error) { | ||
| t.equal(error.code, 'ENOENT') | ||
| t.pass('Temp file was removed after response') | ||
| t.assert.strictEqual(error.code, 'ENOENT') | ||
| t.assert.ok('Temp file was removed after response') | ||
| ee.emit('response') | ||
@@ -431,6 +432,6 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -443,3 +444,3 @@ }) | ||
| } catch (error) { | ||
| t.error(error, 'formData request pump: no err') | ||
| t.assert.ifError(error, 'formData request pump: no err') | ||
| } | ||
@@ -458,3 +459,3 @@ await once(ee, 'response') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -464,3 +465,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| await req.saveRequestFiles() | ||
@@ -495,3 +496,3 @@ return { ok: true } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
@@ -498,0 +499,0 @@ await once(res, 'end') |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -19,3 +19,3 @@ const Fastify = require('fastify') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -25,3 +25,3 @@ await fastify.register(multipart) | ||
| await fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -32,3 +32,3 @@ const files = await req.saveRequestFiles() | ||
| // If it really reused the previously response, their filepath should be the same | ||
| t.equal(files[0].filepath, files2[0].filepath) | ||
| t.assert.strictEqual(files[0].filepath, files2[0].filepath) | ||
@@ -56,5 +56,5 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -14,3 +14,3 @@ const Fastify = require('fastify') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -20,8 +20,8 @@ fastify.register(multipart, { attachFieldsToBody: true }) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const files = await req.saveRequestFiles() | ||
| t.ok(Array.isArray(files)) | ||
| t.equal(files.length, 0) | ||
| t.assert.ok(Array.isArray(files)) | ||
| t.assert.strictEqual(files.length, 0) | ||
@@ -48,6 +48,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -59,3 +59,3 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -65,8 +65,8 @@ fastify.register(multipart, { attachFieldsToBody: 'keyValues' }) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const files = await req.saveRequestFiles() | ||
| t.ok(Array.isArray(files)) | ||
| t.equal(files.length, 0) | ||
| t.assert.ok(Array.isArray(files)) | ||
| t.assert.strictEqual(files.length, 0) | ||
@@ -93,6 +93,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) |
@@ -5,3 +5,3 @@ 'use strict' | ||
| const crypto = require('node:crypto') | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -18,3 +18,3 @@ const Fastify = require('fastify') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -29,12 +29,12 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const part = await req.file() | ||
| t.pass('the file is not consumed yet') | ||
| t.assert.ok('the file is not consumed yet') | ||
| try { | ||
| await part.toBuffer() | ||
| t.fail('it should throw') | ||
| t.assert.fail('it should throw') | ||
| } catch (error) { | ||
| t.ok(error) | ||
| t.assert.ok(error) | ||
| reply.send(error) | ||
@@ -66,7 +66,7 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 413) | ||
| t.assert.strictEqual(res.statusCode, 413) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -79,3 +79,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -90,12 +90,12 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const part = await req.file() | ||
| t.pass('the file is not consumed yet') | ||
| t.assert.ok('the file is not consumed yet') | ||
| try { | ||
| await part.toBuffer() | ||
| t.fail('it should throw') | ||
| t.assert.fail('it should throw') | ||
| } catch (error) { | ||
| t.ok(error) | ||
| t.assert.ok(error) | ||
| reply.send(error) | ||
@@ -130,3 +130,3 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 413) | ||
| t.assert.strictEqual(res.statusCode, 413) | ||
| res.resume() | ||
@@ -137,3 +137,3 @@ await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -146,3 +146,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -158,14 +158,14 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const part = await req.file() | ||
| t.pass('the file is not consumed yet') | ||
| t.assert.ok('the file is not consumed yet') | ||
| try { | ||
| const buffer = await part.toBuffer() | ||
| t.ok(part.file.truncated) | ||
| t.notSame(buffer.length, fileInputLength) | ||
| t.assert.ok(part.file.truncated) | ||
| t.assert.notStrictEqual(buffer.length, fileInputLength) | ||
| reply.send(new fastify.multipartErrors.FilesLimitError()) | ||
| } catch { | ||
| t.fail('it should not throw') | ||
| t.assert.fail('it should not throw') | ||
| } | ||
@@ -197,6 +197,6 @@ }) | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 413) | ||
| t.assert.strictEqual(res.statusCode, 413) | ||
| res.resume() | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -210,3 +210,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -221,3 +221,3 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -230,9 +230,9 @@ const part = await req.file({ | ||
| }) | ||
| t.pass('the file is not consumed yet') | ||
| t.assert.ok('the file is not consumed yet') | ||
| try { | ||
| await part.toBuffer() | ||
| t.fail('it should throw') | ||
| t.assert.fail('it should throw') | ||
| } catch (error) { | ||
| t.ok(error) | ||
| t.assert.ok(error) | ||
| reply.send(error) | ||
@@ -264,7 +264,7 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 413) | ||
| t.assert.strictEqual(res.statusCode, 413) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -277,3 +277,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -289,3 +289,3 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -295,11 +295,11 @@ const part = await req.file({ | ||
| }) | ||
| t.pass('the file is not consumed yet') | ||
| t.assert.ok('the file is not consumed yet') | ||
| try { | ||
| const buffer = await part.toBuffer() | ||
| t.ok(part.file.truncated) | ||
| t.notSame(buffer.length, fileInputLength) | ||
| t.assert.ok(part.file.truncated) | ||
| t.assert.notStrictEqual(buffer.length, fileInputLength) | ||
| reply.send(new fastify.multipartErrors.FilesLimitError()) | ||
| } catch { | ||
| t.fail('it should not throw') | ||
| t.assert.fail('it should not throw') | ||
| } | ||
@@ -331,7 +331,7 @@ }) | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 413) | ||
| t.assert.strictEqual(res.statusCode, 413) | ||
| res.resume() | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -14,5 +14,7 @@ const Fastify = require('fastify') | ||
| test('should respond when all files are processed', function (t) { | ||
| test('should respond when all files are processed', function (t, done) { | ||
| t.plan(3) | ||
| const fastify = Fastify({ http2: true }) | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -24,3 +26,3 @@ fastify.register(multipart) | ||
| for await (const part of parts) { | ||
| t.ok(part.file) | ||
| t.assert.ok(part.file) | ||
| await streamToNull(part.file) | ||
@@ -42,5 +44,5 @@ } | ||
| t.equal(res.headers[':status'], 200) | ||
| t.end() | ||
| t.assert.strictEqual(res.headers[':status'], 200) | ||
| done() | ||
| }) | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -18,3 +18,3 @@ const Fastify = require('fastify') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -24,3 +24,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| const parts = await req.files() | ||
@@ -32,6 +32,6 @@ try { | ||
| } catch (e) { | ||
| t.equal(e.message, 'Premature close', 'File was closed prematurely') | ||
| t.assert.strictEqual(e.message, 'Premature close', 'File was closed prematurely') | ||
| throw e | ||
| } finally { | ||
| t.pass('Finished request') | ||
| t.assert.ok('Finished request') | ||
| } | ||
@@ -57,3 +57,3 @@ return 'ok' | ||
| req.on('error', () => { | ||
| t.pass('ended http request with error') | ||
| t.assert.ok('ended http request with error') | ||
| }) | ||
@@ -65,3 +65,2 @@ const data = form.getBuffer() | ||
| await sleep(100) | ||
| t.end() | ||
| }) | ||
@@ -73,3 +72,3 @@ | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -80,3 +79,3 @@ await fastify.register(multipart) | ||
| fastify.post('/', async function (req) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| try { | ||
@@ -111,7 +110,7 @@ await req.saveRequestFiles() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| for (const tmpUpload of tmpUploads) { | ||
| await t.rejects(fs.access(tmpUpload)) | ||
| await t.assert.rejects(fs.access(tmpUpload)) | ||
| } | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -9,7 +9,7 @@ const Fastify = require('fastify') | ||
| test('should parse JSON fields forms if content-type is set', function (t) { | ||
| test('should parse JSON fields forms if content-type is set', function (t, done) { | ||
| t.plan(5) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -20,5 +20,5 @@ fastify.register(multipart) | ||
| for await (const part of req.parts()) { | ||
| t.notOk(part.filename) | ||
| t.equal(part.mimetype, 'application/json') | ||
| t.same(part.value, { a: 'b' }) | ||
| t.assert.strictEqual(part.filename, undefined) | ||
| t.assert.strictEqual(part.mimetype, 'application/json') | ||
| t.assert.deepStrictEqual(part.value, { a: 'b' }) | ||
| } | ||
@@ -42,6 +42,7 @@ | ||
| const req = http.request(opts, res => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -55,7 +56,7 @@ }) | ||
| test('should not parse JSON fields forms if no content-type is set', function (t) { | ||
| test('should not parse JSON fields forms if no content-type is set', function (t, done) { | ||
| t.plan(5) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -66,5 +67,5 @@ fastify.register(multipart) | ||
| for await (const part of req.parts()) { | ||
| t.notOk(part.filename) | ||
| t.equal(part.mimetype, 'text/plain') | ||
| t.type(part.value, 'string') | ||
| t.assert.strictEqual(part.filename, undefined) | ||
| t.assert.strictEqual(part.mimetype, 'text/plain') | ||
| t.assert.strictEqual(typeof part.value, 'string') | ||
| } | ||
@@ -88,6 +89,7 @@ | ||
| const req = http.request(opts, res => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -102,7 +104,7 @@ }) | ||
| test('should not parse JSON fields forms if non-json content-type is set', function (t) { | ||
| test('should not parse JSON fields forms if non-json content-type is set', function (t, done) { | ||
| t.plan(5) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -113,5 +115,5 @@ fastify.register(multipart) | ||
| for await (const part of req.parts()) { | ||
| t.notOk(part.filename) | ||
| t.equal(part.mimetype, 'text/css') | ||
| t.type(part.value, 'string') | ||
| t.assert.strictEqual(part.filename, undefined) | ||
| t.assert.strictEqual(part.mimetype, 'text/css') | ||
| t.assert.strictEqual(typeof part.value, 'string') | ||
| } | ||
@@ -135,6 +137,7 @@ | ||
| const req = http.request(opts, res => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -149,7 +152,7 @@ }) | ||
| test('should throw error when parsing JSON fields failed', function (t) { | ||
| test('should throw error when parsing JSON fields failed', function (t, done) { | ||
| t.plan(2) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -161,3 +164,3 @@ fastify.register(multipart) | ||
| for await (const part of req.parts()) { | ||
| t.type(part.value, 'string') | ||
| t.assert.strictEqual(typeof part.value, 'string') | ||
| } | ||
@@ -167,3 +170,3 @@ | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.InvalidJSONFieldError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.InvalidJSONFieldError) | ||
| reply.code(500).send() | ||
@@ -186,6 +189,7 @@ } | ||
| const req = http.request(opts, res => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -199,7 +203,7 @@ }) | ||
| test('should always reject JSON parsing if the value was truncated', function (t) { | ||
| test('should always reject JSON parsing if the value was truncated', function (t, done) { | ||
| t.plan(2) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -211,3 +215,3 @@ fastify.register(multipart, { limits: { fieldSize: 2 } }) | ||
| for await (const part of req.parts()) { | ||
| t.type(part.value, 'string') | ||
| t.assert.strictEqual(typeof part.value, 'string') | ||
| } | ||
@@ -217,3 +221,3 @@ | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.InvalidJSONFieldError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.InvalidJSONFieldError) | ||
| reply.code(500).send() | ||
@@ -236,6 +240,7 @@ } | ||
| const req = http.request(opts, res => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -249,7 +254,7 @@ }) | ||
| test('should be able to use JSON schema to validate request when value is a string', function (t) { | ||
| test('should be able to use JSON schema to validate request when value is a string', function (t, done) { | ||
| t.plan(5) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -277,6 +282,6 @@ fastify.register(multipart, { attachFieldsToBody: true, sharedSchemaId: '#mySharedSchema' }) | ||
| async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.same(Object.keys(req.body), ['field']) | ||
| t.equal(req.body.field.value, '{"a":"b"}') | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['field']) | ||
| t.assert.strictEqual(req.body.field.value, '{"a":"b"}') | ||
@@ -300,6 +305,7 @@ reply.code(200).send() | ||
| const req = http.request(opts, res => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -313,7 +319,7 @@ }) | ||
| test('should be able to use JSON schema to validate request when value is a JSON', function (t) { | ||
| test('should be able to use JSON schema to validate request when value is a JSON', function (t, done) { | ||
| t.plan(5) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -338,6 +344,6 @@ fastify.register(multipart, { attachFieldsToBody: true, sharedSchemaId: '#mySharedSchema' }) | ||
| async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| t.same(Object.keys(req.body), ['field']) | ||
| t.same(req.body.field.value, { a: 'b' }) | ||
| t.assert.deepStrictEqual(Object.keys(req.body), ['field']) | ||
| t.assert.deepStrictEqual(req.body.field.value, { a: 'b' }) | ||
@@ -361,6 +367,7 @@ reply.code(200).send() | ||
| const req = http.request(opts, res => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -374,7 +381,7 @@ }) | ||
| test('should return 400 when the field validation fails', function (t) { | ||
| test('should return 400 when the field validation fails', function (t, done) { | ||
| t.plan(2) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -399,3 +406,3 @@ fastify.register(multipart, { attachFieldsToBody: true, sharedSchemaId: '#mySharedSchema' }) | ||
| async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
| reply.code(200).send() | ||
@@ -418,6 +425,7 @@ } | ||
| const req = http.request(opts, res => { | ||
| t.equal(res.statusCode, 400) | ||
| t.assert.strictEqual(res.statusCode, 400) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -424,0 +432,0 @@ }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -16,7 +16,7 @@ const Fastify = require('fastify') | ||
| test('should not allow __proto__ as file name', function (t) { | ||
| test('should not allow __proto__ as file name', function (t, done) { | ||
| t.plan(4) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -26,3 +26,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -33,3 +33,3 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| reply.code(500).send() | ||
@@ -52,6 +52,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -66,7 +67,7 @@ }) | ||
| test('should not allow __proto__ as field name', function (t) { | ||
| test('should not allow __proto__ as field name', function (t, done) { | ||
| t.plan(4) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -76,3 +77,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -83,3 +84,3 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| reply.code(500).send() | ||
@@ -102,6 +103,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -115,7 +117,7 @@ }) | ||
| test('should not allow toString as field name', function (t) { | ||
| test('should not allow toString as field name', function (t, done) { | ||
| t.plan(4) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -125,3 +127,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -132,3 +134,3 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| reply.code(500).send() | ||
@@ -151,6 +153,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -164,7 +167,7 @@ }) | ||
| test('should not allow hasOwnProperty as field name', function (t) { | ||
| test('should not allow hasOwnProperty as field name', function (t, done) { | ||
| t.plan(4) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -174,3 +177,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -181,3 +184,3 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| reply.code(500).send() | ||
@@ -200,6 +203,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -213,7 +217,7 @@ }) | ||
| test('should not allow propertyIsEnumerable as field name', function (t) { | ||
| test('should not allow propertyIsEnumerable as field name', function (t, done) { | ||
| t.plan(4) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -223,3 +227,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -230,3 +234,3 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.PrototypeViolationError) | ||
| reply.code(500).send() | ||
@@ -249,6 +253,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -266,3 +271,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -274,6 +279,6 @@ fastify.register(multipart, { | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart(), 'is multipart') | ||
| t.assert.ok(req.isMultipart(), 'is multipart') | ||
| const part = await req.file() | ||
| t.pass('the file is not consumed yet') | ||
| t.assert.ok('the file is not consumed yet') | ||
@@ -283,5 +288,5 @@ try { | ||
| reply.send('not ok') | ||
| t.fail('it should throw') | ||
| t.assert.fail('it should throw') | ||
| } catch (error) { | ||
| t.ok(error) | ||
| t.assert.ok(error) | ||
| reply.send(error) | ||
@@ -314,13 +319,13 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 413, 'status code equal') | ||
| t.assert.strictEqual(res.statusCode, 413, 'status code equal') | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
| }) | ||
| test('should use default for parts - 1000', function (t) { | ||
| test('should use default for parts - 1000', function (t, done) { | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -333,6 +338,6 @@ fastify.register(multipart) | ||
| for await (const _ of req.parts()) { console.assert(_) } | ||
| t.fail('should throw on 1001') | ||
| t.assert.fail('should throw on 1001') | ||
| reply.code(200).send() | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.PartsLimitError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.PartsLimitError) | ||
| reply.code(500).send() | ||
@@ -355,7 +360,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.end() | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -362,0 +367,0 @@ }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -16,8 +16,7 @@ const Fastify = require('fastify') | ||
| // FIXME, this test fail | ||
| test('should throw fileSize limitation error on small payload', { skip: true }, async function (t) { | ||
| test('should throw fileSize limitation error on small payload', async function (t) { | ||
| t.plan(2) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -27,3 +26,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -33,3 +32,7 @@ const part = await req.file({ limits: { fileSize: 2 } }) | ||
| reply.code(200).send() | ||
| if (part.file.truncated) { | ||
| reply.code(413).send() | ||
| } else { | ||
| reply.code(200).send() | ||
| } | ||
| }) | ||
@@ -57,7 +60,7 @@ | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 413) | ||
| t.assert.strictEqual(res.statusCode, 413) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -70,3 +73,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -76,3 +79,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -105,8 +108,8 @@ const part = await req.file({ limits: { fileSize: 2 }, throwFileSizeLimit: false }) | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
| }) |
| 'use strict' | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -15,3 +15,3 @@ const Fastify = require('fastify') | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -21,3 +21,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -27,6 +27,6 @@ try { | ||
| await file.toBuffer() | ||
| t.fail('should throw') | ||
| t.assert.fail('should throw') | ||
| reply.code(200).send() | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| reply.code(500).send() | ||
@@ -58,7 +58,7 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -71,3 +71,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -77,3 +77,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -83,6 +83,6 @@ try { | ||
| await file.toBuffer() | ||
| t.pass('OK') | ||
| t.assert.ok('OK') | ||
| reply.code(200).send() | ||
| } catch { | ||
| t.fail('Should not throw') | ||
| t.assert.fail('Should not throw') | ||
| reply.code(500).send() | ||
@@ -114,7 +114,7 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -127,3 +127,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -133,3 +133,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -141,6 +141,6 @@ try { | ||
| } | ||
| t.fail('Should throw') | ||
| t.assert.fail('Should throw') | ||
| reply.code(200).send() | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| reply.code(500).send() | ||
@@ -172,7 +172,7 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
@@ -185,3 +185,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -191,3 +191,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -199,6 +199,6 @@ try { | ||
| } | ||
| t.pass('OK') | ||
| t.assert.ok('OK') | ||
| reply.code(200).send() | ||
| } catch { | ||
| t.fail('Should not throw') | ||
| t.assert.fail('Should not throw') | ||
| reply.code(500).send() | ||
@@ -230,8 +230,8 @@ } | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| } catch (error) { | ||
| t.error(error, 'request') | ||
| t.assert.ifError(error) | ||
| } | ||
| }) |
+107
-96
| 'use strict' | ||
| const util = require('node:util') | ||
| const test = require('tap').test | ||
| const test = require('node:test') | ||
| const FormData = require('form-data') | ||
@@ -19,7 +19,7 @@ const Fastify = require('fastify') | ||
| test('should parse forms', function (t) { | ||
| test('should parse forms', function (t, done) { | ||
| t.plan(9) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -31,8 +31,8 @@ fastify.register(multipart) | ||
| if (part.file) { | ||
| t.equal(part.type, 'file') | ||
| t.equal(part.fieldname, 'upload') | ||
| t.equal(part.filename, 'README.md') | ||
| t.equal(part.encoding, '7bit') | ||
| t.equal(part.mimetype, 'text/markdown') | ||
| t.ok(part.fields.upload) | ||
| t.assert.strictEqual(part.type, 'file') | ||
| t.assert.strictEqual(part.fieldname, 'upload') | ||
| t.assert.strictEqual(part.filename, 'README.md') | ||
| t.assert.strictEqual(part.encoding, '7bit') | ||
| t.assert.strictEqual(part.mimetype, 'text/markdown') | ||
| t.assert.ok(part.fields.upload) | ||
@@ -43,3 +43,3 @@ const original = fs.readFileSync(filePath, 'utf8') | ||
| concat(function (buf) { | ||
| t.equal(buf.toString(), original) | ||
| t.assert.strictEqual(buf.toString(), original) | ||
| }) | ||
@@ -66,7 +66,8 @@ ) | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| // consume all data without processing | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -83,7 +84,7 @@ }) | ||
| test('should respond when all files are processed', function (t) { | ||
| test('should respond when all files are processed', function (t, done) { | ||
| t.plan(6) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -95,4 +96,4 @@ fastify.register(multipart) | ||
| for await (const part of parts) { | ||
| t.ok(part.file) | ||
| t.equal(part.type, 'file') | ||
| t.assert.ok(part.file) | ||
| t.assert.strictEqual(part.type, 'file') | ||
| await streamToNull(part.file) | ||
@@ -116,6 +117,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -132,7 +134,7 @@ }) | ||
| test('should group parts with the same name to an array', function (t) { | ||
| test('should group parts with the same name to an array', function (t, done) { | ||
| t.plan(15) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -144,8 +146,8 @@ fastify.register(multipart) | ||
| for await (const part of parts) { | ||
| t.ok(part) | ||
| t.assert.ok(part) | ||
| if (Array.isArray(part.fields.upload)) { | ||
| t.pass('multiple fields are grouped by array') | ||
| t.assert.ok('multiple fields are grouped by array') | ||
| } | ||
| if (Array.isArray(part.fields.hello)) { | ||
| t.pass('multiple files are grouped by array') | ||
| t.assert.ok('multiple files are grouped by array') | ||
| } | ||
@@ -172,6 +174,7 @@ if (part.file) { | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -190,7 +193,7 @@ }) | ||
| test('should error if it is not multipart', function (t) { | ||
| test('should error if it is not multipart', function (t, done) { | ||
| t.plan(3) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -200,3 +203,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.notOk(req.isMultipart()) | ||
| t.assert.ok(!req.isMultipart()) | ||
@@ -207,3 +210,3 @@ try { | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.InvalidMultipartContentTypeError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.InvalidMultipartContentTypeError) | ||
| reply.code(500).send() | ||
@@ -227,3 +230,4 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| done() | ||
| }) | ||
@@ -234,7 +238,7 @@ req.end(JSON.stringify({ hello: 'world' })) | ||
| test('should error if boundary is empty', function (t) { | ||
| test('should error if boundary is empty', function (t, done) { | ||
| t.plan(3) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -244,3 +248,3 @@ fastify.register(multipart) | ||
| fastify.post('/', async function (req, reply) { | ||
| t.ok(req.isMultipart()) | ||
| t.assert.ok(req.isMultipart()) | ||
@@ -251,3 +255,3 @@ try { | ||
| } catch (error) { | ||
| t.equal(error.message, 'Multipart: Boundary not found') | ||
| t.assert.strictEqual(error.message, 'Multipart: Boundary not found') | ||
| reply.code(500).send() | ||
@@ -272,3 +276,4 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| done() | ||
| }) | ||
@@ -280,5 +285,5 @@ | ||
| test('should throw error due to filesLimit (The max number of file fields (Default: Infinity))', function (t) { | ||
| test('should throw error due to filesLimit (The max number of file fields (Default: Infinity))', function (t, done) { | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -291,3 +296,3 @@ fastify.register(multipart) | ||
| for await (const part of parts) { | ||
| t.ok(part.file, 'part received') | ||
| t.assert.ok(part.file, 'part received') | ||
| await streamToNull(part.file) | ||
@@ -297,3 +302,3 @@ } | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.FilesLimitError, 'error') | ||
| t.assert.ok(error instanceof fastify.multipartErrors.FilesLimitError, 'error') | ||
| reply.code(500).send() | ||
@@ -317,3 +322,3 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500, 'status code') | ||
| t.assert.strictEqual(res.statusCode, 500, 'status code') | ||
| res.resume() | ||
@@ -325,4 +330,4 @@ res.on('end', () => { | ||
| ended = true | ||
| t.pass('res ended successfully') | ||
| t.end() | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -338,4 +343,4 @@ }) | ||
| ended = true | ||
| t.equal(err.code, 'ECONNRESET') | ||
| t.end() | ||
| t.assert.strictEqual(err.code, 'ECONNRESET') | ||
| done() | ||
| }) | ||
@@ -345,5 +350,5 @@ }) | ||
| test('should be able to configure limits globally with plugin register options', function (t) { | ||
| test('should be able to configure limits globally with plugin register options', function (t, done) { | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -356,4 +361,4 @@ fastify.register(multipart, { limits: { files: 1 } }) | ||
| for await (const part of parts) { | ||
| t.ok(part.file) | ||
| t.equal(part.type, 'file') | ||
| t.assert.ok(part.file) | ||
| t.assert.strictEqual(part.type, 'file') | ||
| await streamToNull(part.file) | ||
@@ -363,3 +368,3 @@ } | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.FilesLimitError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.FilesLimitError) | ||
| reply.code(500).send() | ||
@@ -383,3 +388,3 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
@@ -391,4 +396,4 @@ res.on('end', () => { | ||
| ended = true | ||
| t.pass('res ended successfully') | ||
| t.end() | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -403,4 +408,4 @@ }) | ||
| ended = true | ||
| t.equal(err.code, 'ECONNRESET') | ||
| t.end() | ||
| t.assert.strictEqual(err.code, 'ECONNRESET') | ||
| done() | ||
| }) | ||
@@ -412,7 +417,7 @@ | ||
| test('should throw error due to fieldsLimit (Max number of non-file fields (Default: Infinity))', function (t) { | ||
| test('should throw error due to fieldsLimit (Max number of non-file fields (Default: Infinity))', function (t, done) { | ||
| t.plan(4) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -424,7 +429,7 @@ fastify.register(multipart) | ||
| for await (const part of req.parts({ limits: { fields: 1 } })) { | ||
| t.ok(part) | ||
| t.assert.ok(part) | ||
| } | ||
| reply.code(200).send() | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.FieldsLimitError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.FieldsLimitError) | ||
| reply.code(500).send() | ||
@@ -447,6 +452,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -461,7 +467,7 @@ }) | ||
| test('should throw error due to partsLimit (The max number of parts (fields + files) (Default: Infinity))', function (t) { | ||
| test('should throw error due to partsLimit (The max number of parts (fields + files) (Default: Infinity))', function (t, done) { | ||
| t.plan(4) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -473,7 +479,7 @@ fastify.register(multipart) | ||
| for await (const part of req.parts({ limits: { parts: 1 } })) { | ||
| t.ok(part) | ||
| t.assert.ok(part) | ||
| } | ||
| reply.code(200).send() | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.PartsLimitError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.PartsLimitError) | ||
| reply.code(500).send() | ||
@@ -496,6 +502,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -510,7 +517,7 @@ }) | ||
| test('should throw error due to file size limit exceed (Default: true)', function (t) { | ||
| t.plan(6) | ||
| test('should throw error due to file size limit exceed (Default: true)', function (t, done) { | ||
| t.plan(7) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -523,4 +530,4 @@ fastify.register(multipart, { limits: { fileSize: 1 } }) | ||
| for await (const part of parts) { | ||
| t.ok(part.file) | ||
| t.equal(part.type, 'file') | ||
| t.assert.ok(part.file) | ||
| t.assert.strictEqual(part.type, 'file') | ||
| await streamToNull(part.file) | ||
@@ -530,3 +537,3 @@ } | ||
| } catch (error) { | ||
| t.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| t.assert.ok(error instanceof fastify.multipartErrors.RequestFileTooLargeError) | ||
| reply.code(500).send() | ||
@@ -549,5 +556,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 500) | ||
| t.assert.strictEqual(res.statusCode, 500) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -562,7 +571,7 @@ }) | ||
| test('should not throw error due to file size limit exceed - files setting (Default: true)', function (t) { | ||
| t.plan(5) | ||
| test('should not throw error due to file size limit exceed - files setting (Default: true)', function (t, done) { | ||
| t.plan(6) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -574,4 +583,4 @@ fastify.register(multipart, { throwFileSizeLimit: false }) | ||
| for await (const part of parts) { | ||
| t.ok(part.file) | ||
| t.equal(part.type, 'file') | ||
| t.assert.ok(part.file) | ||
| t.assert.strictEqual(part.type, 'file') | ||
| await streamToNull(part.file) | ||
@@ -595,5 +604,7 @@ } | ||
| const req = http.request(opts, (res) => { | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| res.on('end', () => { | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| done() | ||
| }) | ||
@@ -614,3 +625,3 @@ }) | ||
| const fastify = Fastify() | ||
| t.teardown(fastify.close.bind(fastify)) | ||
| t.after(() => fastify.close()) | ||
@@ -628,8 +639,8 @@ fastify.register(multipart) | ||
| if (part.file) { | ||
| t.equal(part.type, 'file') | ||
| t.equal(part.fieldname, 'upload') | ||
| t.equal(part.filename, 'README.md') | ||
| t.equal(part.encoding, '7bit') | ||
| t.equal(part.mimetype, 'text/markdown') | ||
| t.ok(part.fields.upload) | ||
| t.assert.strictEqual(part.type, 'file') | ||
| t.assert.strictEqual(part.fieldname, 'upload') | ||
| t.assert.strictEqual(part.filename, 'README.md') | ||
| t.assert.strictEqual(part.encoding, '7bit') | ||
| t.assert.strictEqual(part.mimetype, 'text/markdown') | ||
| t.assert.ok(part.fields.upload) | ||
@@ -639,3 +650,3 @@ await pump( | ||
| concat(function (buf) { | ||
| t.equal(buf.toString(), original) | ||
| t.assert.strictEqual(buf.toString(), original) | ||
| }) | ||
@@ -649,5 +660,5 @@ ) | ||
| t.equal(recvField.upload, true) | ||
| t.equal(recvField.hello, true) | ||
| t.equal(recvField.willbe, true) | ||
| t.assert.ok(recvField.upload) | ||
| t.assert.ok(recvField.hello) | ||
| t.assert.ok(recvField.willbe) | ||
@@ -679,6 +690,6 @@ reply.code(200).send() | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully') | ||
| t.assert.ok('res ended successfully') | ||
| }) | ||
@@ -733,8 +744,8 @@ | ||
| const [res] = await once(req, 'response') | ||
| t.equal(res.statusCode, 200) | ||
| t.assert.strictEqual(res.statusCode, 200) | ||
| res.resume() | ||
| await once(res, 'end') | ||
| t.pass('res ended successfully!') | ||
| t.assert.ok('res ended successfully!') | ||
| await app.close() | ||
| }) |
| 'use strict' | ||
| const tap = require('tap') | ||
| const test = require('node:test') | ||
| const { Readable } = require('node:stream') | ||
| const streamToNull = require('../lib/stream-consumer') | ||
| tap.test('does what it should', async t => { | ||
| test('does what it should', async t => { | ||
| t.plan(1) | ||
| let count = 1_000_000 | ||
@@ -21,6 +22,7 @@ const stream = new Readable({ | ||
| await streamToNull(stream) | ||
| t.pass() | ||
| t.assert.ok(true) | ||
| }) | ||
| tap.test('handles close event', async t => { | ||
| test('handles close event', async t => { | ||
| t.plan(1) | ||
| let count = 1_000_000 | ||
@@ -39,6 +41,7 @@ const stream = new Readable({ | ||
| await streamToNull(stream) | ||
| t.pass() | ||
| t.assert.ok(true) | ||
| }) | ||
| tap.test('handles error event', async t => { | ||
| test('handles error event', async t => { | ||
| t.plan(1) | ||
| let count = 1_000_000 | ||
@@ -59,4 +62,4 @@ const stream = new Readable({ | ||
| } catch (error) { | ||
| t.match(error, /boom/) | ||
| t.assert.match(error.toString(), /boom/) | ||
| } | ||
| }) |
+0
-8
@@ -46,10 +46,2 @@ import { BusboyConfig, BusboyFileStream } from '@fastify/busboy' | ||
| type MultipartHandler = ( | ||
| field: string, | ||
| file: BusboyFileStream, | ||
| filename: string, | ||
| encoding: string, | ||
| mimetype: string | ||
| ) => void | ||
| interface BodyEntry { | ||
@@ -56,0 +48,0 @@ data: Buffer; |
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
164136
3.99%16
-5.88%4606
1.95%540
2.27%6
20%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated