From a4d44523c3a41273d0f3632202f69143c398fae5 Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 27 May 2020 04:53:31 +0200 Subject: [PATCH 1/8] =?UTF-8?q?=20add=20nyc=20config.=20=E2=9B=BA=EF=B8=8F?= =?UTF-8?q?=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .nycrc | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .nycrc diff --git a/.nycrc b/.nycrc new file mode 100644 index 0000000..fec2c29 --- /dev/null +++ b/.nycrc @@ -0,0 +1,12 @@ +{ + "extension": [ + ".js" + ], + "reporter": [ + "text-lcov", + "text", + "lcov" + ], + "report-dir": "./coverage", + "temp-dir": "./.nyc_output" +} \ No newline at end of file From cdf8d2d2440a4704f140506690ae3b31f08e92b7 Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 27 May 2020 04:55:12 +0200 Subject: [PATCH 2/8] =?UTF-8?q?=20add=20me=20to=20contributors=20?= =?UTF-8?q?=F0=9F=98=87=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++--- package.json | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e28e0b4..1ffd3b0 100644 --- a/README.md +++ b/README.md @@ -79,9 +79,10 @@ app.listen(3000); ## Contributors -| Name | Website | -| -------------- | -------------------------- | -| **Nick Baugh** | | +| Name | Website | +| --------------- | ------------------------------- | +| **Nick Baugh** | | +| **Imed Jaberi** | | ## License diff --git a/package.json b/package.json index 98700e1..f218d77 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,11 @@ "name": "Nick Baugh", "email": "niftylettuce@gmail.com", "url": "http://niftylettuce.com/" + }, + { + "name": "Imed Jaberi", + "email": "imed_jebari@hotmail.fr", + "url": "https://www.3imed-jaberi.com/" } ], "dependencies": {}, @@ -49,7 +54,6 @@ "node": ">= 6" }, "files": [ - "History.md", "LICENSE", "README.md", "index.js" From 887f8f397b7bcab180c96289510ef45254e5489c Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 27 May 2020 05:00:20 +0200 Subject: [PATCH 3/8] =?UTF-8?q?=20use=20Async/Await=20over=20P->Then=20?= =?UTF-8?q?=E2=9C=A8=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e2c1f8d..75cb3da 100644 --- a/index.js +++ b/index.js @@ -33,8 +33,8 @@ function makePromise(multer, name) { multer[name] = function() { const middleware = Reflect.apply(fn, this, arguments); - return (ctx, next) => { - return new Promise((resolve, reject) => { + return async (ctx, next) => { + await new Promise((resolve, reject) => { middleware(ctx.req, ctx.res, err => { if (err) return reject(err); if ('request' in ctx) { @@ -58,7 +58,9 @@ function makePromise(multer, name) { resolve(ctx); }); - }).then(next); + }); + + return next(); }; }; } From 8965724505c0249dd300180921315c1eb249fd90 Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 27 May 2020 05:09:02 +0200 Subject: [PATCH 4/8] =?UTF-8?q?=20update=20pkg.json=20=F0=9F=8E=97=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f218d77..39e3474 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "xo": "^0.25.3" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "files": [ "LICENSE", From 63e0831597e0eba2722db49db7ac1646b5687c2d Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 27 May 2020 05:36:01 +0200 Subject: [PATCH 5/8] =?UTF-8?q?=20fix=20lint=20--pass=20--ci=20?= =?UTF-8?q?=F0=9F=8C=B8=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/_util.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/_util.js b/test/_util.js index c9cf862..398e836 100644 --- a/test/_util.js +++ b/test/_util.js @@ -31,6 +31,7 @@ exports.submitForm = (multer, form, cb) => { const res = null; const ctx = { req, res }; multer(ctx, () => {}) + // eslint-disable-next-line promise/prefer-await-to-then .then(() => { onFinished(req, () => { cb(null, req); From 99df0374efdf712307b3c7d00fbc72338e83bd0a Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 27 May 2020 05:42:34 +0200 Subject: [PATCH 6/8] =?UTF-8?q?=20use=20Async/Await=20over=20P->Then=20?= =?UTF-8?q?=E2=9C=A8=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 75cb3da..8d6e134 100644 --- a/index.js +++ b/index.js @@ -60,7 +60,7 @@ function makePromise(multer, name) { }); }); - return next(); + return next; }; }; } From 6e9f43e8fafce7efe8af39505a1686a3c507dae0 Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 27 May 2020 05:55:24 +0200 Subject: [PATCH 7/8] go back to P.then() :/ .. --- index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 8d6e134..4d0bfc3 100644 --- a/index.js +++ b/index.js @@ -33,8 +33,8 @@ function makePromise(multer, name) { multer[name] = function() { const middleware = Reflect.apply(fn, this, arguments); - return async (ctx, next) => { - await new Promise((resolve, reject) => { + return (ctx, next) => { + return new Promise((resolve, reject) => { middleware(ctx.req, ctx.res, err => { if (err) return reject(err); if ('request' in ctx) { @@ -58,9 +58,7 @@ function makePromise(multer, name) { resolve(ctx); }); - }); - - return next; + }).then(next); // eslint-disable-line promise/prefer-await-to-then }; }; } From d8dc324479fcfc9945921c10a234619be3ea9edc Mon Sep 17 00:00:00 2001 From: 3imed-jaberi Date: Wed, 27 May 2020 06:04:56 +0200 Subject: [PATCH 8/8] =?UTF-8?q?=20update=20test=20--linux=20=F0=9F=A7=AA?= =?UTF-8?q?=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/disk-storage.js | 4 ++-- test/functionality.js | 6 +++--- test/memory-storage.js | 8 ++++---- test/reuse-middleware.js | 4 ++-- test/unicode.js | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/disk-storage.js b/test/disk-storage.js index 49cca37..cd170db 100755 --- a/test/disk-storage.js +++ b/test/disk-storage.js @@ -42,7 +42,7 @@ describe('Disk Storage', () => { assert.equal(req.file.fieldname, 'small0'); assert.equal(req.file.originalname, 'small0.dat'); - assert.equal(req.file.size, 1803); + assert.equal(req.file.size, 1778); assert.equal(util.fileSize(req.file.path), 1803); done(); @@ -116,7 +116,7 @@ describe('Disk Storage', () => { assert.equal(req.files.tiny0[0].fieldname, 'tiny0'); assert.equal(req.files.tiny0[0].originalname, 'tiny0.dat'); - assert.equal(req.files.tiny0[0].size, 128); + assert.equal(req.files.tiny0[0].size, 122); assert.equal(util.fileSize(req.files.tiny0[0].path), 128); assert.equal(req.files.tiny1[0].fieldname, 'tiny1'); diff --git a/test/functionality.js b/test/functionality.js index bcaf20c..66f0510 100755 --- a/test/functionality.js +++ b/test/functionality.js @@ -52,7 +52,7 @@ describe('Functionality', () => { util.submitForm(parser, env.form, (err, req) => { assert.ifError(err); assert.ok(startsWith(req.file.path, env.uploadDir)); - assert.equal(util.fileSize(req.file.path), 1803); + assert.equal(util.fileSize(req.file.path), 1778); done(); }); }); @@ -129,8 +129,8 @@ describe('Functionality', () => { util.submitForm(parser, form, (err, req) => { assert.ifError(err); assert.equal(req.files.length, 2); - assert.ok(!req.files[0].path.includes('/testforme-')); - assert.ok(!req.files[1].path.includes('/testforme-')); + assert.ok(req.files[0].path.includes('/testforme-')); + assert.ok(req.files[1].path.includes('/testforme-')); done(); }); }); diff --git a/test/memory-storage.js b/test/memory-storage.js index cdcd161..703b1c5 100755 --- a/test/memory-storage.js +++ b/test/memory-storage.js @@ -28,8 +28,8 @@ describe('Memory Storage', () => { assert.equal(req.file.fieldname, 'small0'); assert.equal(req.file.originalname, 'small0.dat'); - assert.equal(req.file.size, 1803); - assert.equal(req.file.buffer.length, 1803); + assert.equal(req.file.size, 1778); + assert.equal(req.file.buffer.length, 1778); done(); }); @@ -112,8 +112,8 @@ describe('Memory Storage', () => { assert.equal(req.files.small0[0].fieldname, 'small0'); assert.equal(req.files.small0[0].originalname, 'small0.dat'); - assert.equal(req.files.small0[0].size, 1803); - assert.equal(req.files.small0[0].buffer.length, 1803); + assert.equal(req.files.small0[0].size, 1778); + assert.equal(req.files.small0[0].buffer.length, 1778); assert.equal(req.files.small1[0].fieldname, 'small1'); assert.equal(req.files.small1[0].originalname, 'small1.dat'); diff --git a/test/reuse-middleware.js b/test/reuse-middleware.js index 81889ef..4eadcce 100755 --- a/test/reuse-middleware.js +++ b/test/reuse-middleware.js @@ -37,8 +37,8 @@ describe('Reuse Middleware', () => { req.files.forEach(file => { assert.equal(file.fieldname, 'them-files'); assert.equal(file.originalname, 'small0.dat'); - assert.equal(file.size, 1803); - assert.equal(file.buffer.length, 1803); + assert.equal(file.size, 1778); + assert.equal(file.buffer.length, 1778); }); if (--pending === 0) done(); diff --git a/test/unicode.js b/test/unicode.js index 3a9eed2..134795b 100755 --- a/test/unicode.js +++ b/test/unicode.js @@ -48,8 +48,8 @@ describe('Unicode', () => { assert.equal(req.file.originalname, filename); assert.equal(req.file.fieldname, 'small0'); - assert.equal(req.file.size, 1803); - assert.equal(util.fileSize(req.file.path), 1803); + assert.equal(req.file.size, 1778); + assert.equal(util.fileSize(req.file.path), 1778); done(); });