middlewarify
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -9,3 +9,3 @@ /** | ||
const noopMidd = function(cb) { | ||
const noopMidd = function (cb) { | ||
if (__.isFunction(cb)) { | ||
@@ -25,3 +25,3 @@ cb(); | ||
/** | ||
* Apply the middleware pattern to the provided object's propert. | ||
* Apply the middleware pattern to the provided object's property. | ||
* | ||
@@ -37,3 +37,3 @@ * @param {Object} obj An Object. | ||
*/ | ||
middlewarify.make = function(obj, prop, optFinalCb, optParams) { | ||
middlewarify.make = function (obj, prop, optFinalCb, optParams) { | ||
const middObj = middlewarify.newMidd(); | ||
@@ -102,3 +102,3 @@ | ||
*/ | ||
middlewarify.newMidd = function() { | ||
middlewarify.newMidd = function () { | ||
const middObj = Object.create(null); | ||
@@ -166,3 +166,3 @@ middObj.mainCallback = noopMidd; | ||
*/ | ||
middlewarify._prepareMiddleware = middObj => { | ||
middlewarify._prepareMiddleware = (middObj) => { | ||
let midds; | ||
@@ -192,3 +192,3 @@ if (middObj.params.beforeAfter) { | ||
*/ | ||
middlewarify._syncShiftAndInvoke = function( | ||
middlewarify._syncShiftAndInvoke = function ( | ||
midds, | ||
@@ -237,3 +237,3 @@ args, | ||
*/ | ||
middlewarify._asyncShiftAndInvoke = async function( | ||
middlewarify._asyncShiftAndInvoke = async function ( | ||
midds, | ||
@@ -280,3 +280,3 @@ args, | ||
*/ | ||
middlewarify._use = function(middObj, middType, ...middlewares) { | ||
middlewarify._use = function (middObj, middType, ...middlewares) { | ||
const len = middlewares.length; | ||
@@ -309,5 +309,5 @@ if (len === 0) { | ||
middlewares.forEach(function(middleware) { | ||
middlewares.forEach(function (middleware) { | ||
if (Array.isArray(middleware)) { | ||
middleware.forEach(function(argFn) { | ||
middleware.forEach(function (argFn) { | ||
if (__.isFunction(argFn)) { | ||
@@ -314,0 +314,0 @@ pushMidd(argFn); |
{ | ||
"name": "middlewarify", | ||
"description": "Apply the middleware pattern to any function.", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"homepage": "https://github.com/thanpolas/middlewarify", | ||
@@ -29,19 +29,19 @@ "author": { | ||
"dependencies": { | ||
"lodash": "~4.17.15", | ||
"async": "~3.2.0" | ||
"lodash": "4.17.20", | ||
"async": "3.2.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "~4.2.0", | ||
"eslint": "~6.8.0", | ||
"eslint-config-airbnb-base": "~14.0.0", | ||
"eslint-config-prettier": "~6.10.0", | ||
"eslint-plugin-import": "~2.20.1", | ||
"eslint-plugin-jest": "~23.8.2", | ||
"eslint-plugin-jsdoc": "~22.0.0", | ||
"eslint-plugin-prettier": "~3.1.2", | ||
"eslint": "~7.12.1", | ||
"eslint-config-airbnb-base": "~14.2.0", | ||
"eslint-config-prettier": "~6.15.0", | ||
"eslint-plugin-import": "~2.22.1", | ||
"eslint-plugin-jest": "~24.1.0", | ||
"eslint-plugin-jsdoc": "~30.7.3", | ||
"eslint-plugin-prettier": "~3.1.4", | ||
"eslint-plugin-security": "~1.4.0", | ||
"mocha": "~7.1.0", | ||
"prettier": "~1.19.1", | ||
"release-it": "^13.0.2", | ||
"sinon": "~9.0.0" | ||
"mocha": "~8.2.0", | ||
"prettier": "~2.1.2", | ||
"release-it": "^14.2.0", | ||
"sinon": "~9.2.1" | ||
}, | ||
@@ -48,0 +48,0 @@ "keywords": [ |
@@ -332,2 +332,4 @@ # Middlewarify | ||
- **v2.0.1**, _30 Oct 2020_ | ||
- Updated all dependencies to latest. | ||
- **v2.0.0**, _09 Mar 2020_ **Breaking Changes** | ||
@@ -334,0 +336,0 @@ - Middlewarify will now execute all middleware synchronously by default. |
@@ -7,10 +7,10 @@ /** | ||
const midd = require('../'); | ||
const midd = require('..'); | ||
const noop = function() {}; | ||
const noop = function () {}; | ||
suite('8. Before / After / Last middleware Asynchronous', function() { | ||
setup(function() {}); | ||
suite('8. Before / After / Last middleware Asynchronous', function () { | ||
setup(function () {}); | ||
teardown(function() {}); | ||
teardown(function () {}); | ||
@@ -21,3 +21,3 @@ // The numbering (e.g. 1.1.1) has nothing to do with order | ||
test('8.1 Types Test', function() { | ||
test('8.1 Types Test', function () { | ||
const obj = Object.create(null); | ||
@@ -51,3 +51,3 @@ midd.make(obj, 'create', { | ||
suite('8.2. middleware before/after Sequence of invocation', function() { | ||
suite('8.2. middleware before/after Sequence of invocation', function () { | ||
let obj; | ||
@@ -63,3 +63,3 @@ let midd1; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
@@ -77,6 +77,6 @@ midd1 = sinon.spy(); | ||
teardown(function(done) { | ||
teardown(function (done) { | ||
obj | ||
.create() | ||
.then(function() { | ||
.then(function () { | ||
assert.ok( | ||
@@ -132,3 +132,3 @@ midd1.calledOnce, | ||
test('8.2.1 Multiple arguments', function() { | ||
test('8.2.1 Multiple arguments', function () { | ||
obj.create.before(midd1, midd2, midd3); | ||
@@ -138,3 +138,3 @@ obj.create.last(middFinal); | ||
}); | ||
test('8.2.2 Multiple calls', function() { | ||
test('8.2.2 Multiple calls', function () { | ||
obj.create.last(middFinal); | ||
@@ -148,3 +148,3 @@ obj.create.before(midd1); | ||
}); | ||
test('8.2.3 An array', function() { | ||
test('8.2.3 An array', function () { | ||
obj.create.before([midd1, midd2, midd3]); | ||
@@ -154,3 +154,3 @@ obj.create.last([middFinal]); | ||
}); | ||
test('8.2.4 Array mixed with arg', function() { | ||
test('8.2.4 Array mixed with arg', function () { | ||
obj.create.before([midd1, midd2], midd3); | ||
@@ -162,3 +162,3 @@ obj.create.last(middFinal); | ||
suite('8.3. middleware() argument piping', function() { | ||
suite('8.3. middleware() argument piping', function () { | ||
let obj; | ||
@@ -170,7 +170,7 @@ let mainMidd; | ||
let lastMidd; | ||
setup(function() {}); | ||
setup(function () {}); | ||
teardown(function() {}); | ||
teardown(function () {}); | ||
test('8.3.1 Three arguments', function(done) { | ||
test('8.3.1 Three arguments', function (done) { | ||
obj = Object.create(null); | ||
@@ -191,3 +191,3 @@ mainMidd = sinon.spy(); | ||
.create(1, foo, bar) | ||
.then(function() { | ||
.then(function () { | ||
assert.ok( | ||
@@ -217,6 +217,6 @@ firstMidd.alwaysCalledWith(1, foo, bar), | ||
}); | ||
suite('8.3.2 Main Callback arguments pipes to final promise', function() { | ||
suite('8.3.2 Main Callback arguments pipes to final promise', function () { | ||
function invoke(returnValue) { | ||
obj = Object.create(null); | ||
mainMidd = function() { | ||
mainMidd = function () { | ||
return returnValue; | ||
@@ -231,4 +231,4 @@ }; | ||
} | ||
test('8.3.2.1 Using a promise', function(done) { | ||
const prom = new Promise(function(resolve) { | ||
test('8.3.2.1 Using a promise', function (done) { | ||
const prom = new Promise(function (resolve) { | ||
resolve('value'); | ||
@@ -240,3 +240,3 @@ }); | ||
.create() | ||
.then(function(val) { | ||
.then(function (val) { | ||
assert.equal(val, 'value'); | ||
@@ -246,7 +246,7 @@ }) | ||
}); | ||
test('8.3.2.2 Using a string', function(done) { | ||
test('8.3.2.2 Using a string', function (done) { | ||
invoke('value'); | ||
obj | ||
.create() | ||
.then(function(val) { | ||
.then(function (val) { | ||
assert.equal(val, 'value'); | ||
@@ -256,7 +256,7 @@ }) | ||
}); | ||
test('8.3.2.3 Using a number', function(done) { | ||
test('8.3.2.3 Using a number', function (done) { | ||
invoke(9); | ||
obj | ||
.create() | ||
.then(function(val) { | ||
.then(function (val) { | ||
assert.equal(val, 9); | ||
@@ -269,10 +269,10 @@ }) | ||
suite('8.5. Failing middleware cases', function() { | ||
suite('8.5. Failing middleware cases', function () { | ||
let obj; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
midd.make(obj, 'create', { beforeAfter: true, async: true }); | ||
}); | ||
test('8.5.1.1 Before middleware throws an error', function(done) { | ||
obj.create.before(function() { | ||
test('8.5.1.1 Before middleware throws an error', function (done) { | ||
obj.create.before(function () { | ||
throw new Error('an error'); | ||
@@ -283,3 +283,3 @@ }); | ||
.create() | ||
.then(null, function(err) { | ||
.then(null, function (err) { | ||
assert.instanceOf(err, Error); | ||
@@ -292,4 +292,4 @@ assert.equal(err.message, 'an error'); | ||
test('8.5.1.1.2 After middleware throws an error', function(done) { | ||
obj.create.after(function() { | ||
test('8.5.1.1.2 After middleware throws an error', function (done) { | ||
obj.create.after(function () { | ||
throw new Error('an error'); | ||
@@ -300,3 +300,3 @@ }); | ||
.create() | ||
.then(null, function(err) { | ||
.then(null, function (err) { | ||
assert.instanceOf(err, Error); | ||
@@ -309,3 +309,3 @@ assert.equal(err.message, 'an error'); | ||
test('8.5.1.2 Main callback throws an error', function(done) { | ||
test('8.5.1.2 Main callback throws an error', function (done) { | ||
const custObj = Object.create(null); | ||
@@ -315,3 +315,3 @@ midd.make( | ||
'create', | ||
function() { | ||
function () { | ||
throw new Error('an error'); | ||
@@ -326,3 +326,3 @@ }, | ||
noop, | ||
function(err) { | ||
function (err) { | ||
assert.instanceOf(err, Error, '"err" should be instanceOf Error'); | ||
@@ -336,6 +336,6 @@ assert.equal(err.message, 'an error', 'Error message should match'); | ||
}); | ||
test('8.5.1.3 Main callback throws an error async', function(done) { | ||
test('8.5.1.3 Main callback throws an error async', function (done) { | ||
function promiseAsyncReject() { | ||
return new Promise(function(resolve, reject) { | ||
setTimeout(function() { | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { | ||
reject(new Error('an error')); | ||
@@ -350,4 +350,4 @@ }); | ||
'create', | ||
function() { | ||
return promiseAsyncReject().catch(function(err) { | ||
function () { | ||
return promiseAsyncReject().catch(function (err) { | ||
throw err; | ||
@@ -363,3 +363,3 @@ }); | ||
noop, | ||
function(err) { | ||
function (err) { | ||
assert.instanceOf(err, Error, '"err" should be instanceOf Error'); | ||
@@ -374,14 +374,14 @@ assert.equal(err.message, 'an error', 'Error message should match'); | ||
}); | ||
suite('8.6. Resolving Value propagation to After middl', function() { | ||
suite('8.6. Resolving Value propagation to After middl', function () { | ||
let obj; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
}); | ||
test('8.6.1 resolving value gets passed as an extra argument by promise', function(done) { | ||
test('8.6.1 resolving value gets passed as an extra argument by promise', function (done) { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
return new Promise(function(resolve) { | ||
setTimeout(function() { | ||
function () { | ||
return new Promise(function (resolve) { | ||
setTimeout(function () { | ||
resolve('abc'); | ||
@@ -394,3 +394,3 @@ }); | ||
obj.create.after(function(arg1, arg2, resolveValue) { | ||
obj.create.after(function (arg1, arg2, resolveValue) { | ||
assert.equal(resolveValue, 'abc'); | ||
@@ -400,7 +400,7 @@ }); | ||
}); | ||
test('8.6.2 resolving value gets passed as an extra argument by returning', function(done) { | ||
test('8.6.2 resolving value gets passed as an extra argument by returning', function (done) { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
function () { | ||
return 'abc'; | ||
@@ -411,3 +411,3 @@ }, | ||
obj.create.after(function(arg1, arg2, resolveValue) { | ||
obj.create.after(function (arg1, arg2, resolveValue) { | ||
assert.equal(resolveValue, 'abc'); | ||
@@ -419,12 +419,12 @@ }); | ||
suite('8.7 Unhandled errors', function() { | ||
suite('8.7 Unhandled errors', function () { | ||
let obj; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
}); | ||
test('8.7.1 Throwing errors does not cause Unhandled exceptions', function(done) { | ||
test('8.7.1 Throwing errors does not cause Unhandled exceptions', function (done) { | ||
midd.make( | ||
obj, | ||
'create', | ||
async function() { | ||
async function () { | ||
throw new Error('Boo'); | ||
@@ -437,3 +437,3 @@ }, | ||
.create() | ||
.catch(function(err) { | ||
.catch(function (err) { | ||
assert.equal(err.message, 'Boo'); | ||
@@ -444,5 +444,5 @@ assert.instanceOf(err, Error); | ||
}); | ||
test('8.7.2 Throwing errors does not cause Unhandled exceptions', function(done) { | ||
test('8.7.2 Throwing errors does not cause Unhandled exceptions', function (done) { | ||
function prom() { | ||
return new Promise(function(resolve) { | ||
return new Promise(function (resolve) { | ||
setTimeout(resolve, 1000); | ||
@@ -455,4 +455,4 @@ }); | ||
'create', | ||
async function() { | ||
return prom().then(function() { | ||
async function () { | ||
return prom().then(function () { | ||
throw new Error('Boo'); | ||
@@ -466,3 +466,3 @@ }); | ||
.create() | ||
.catch(function(err) { | ||
.catch(function (err) { | ||
assert.equal(err.message, 'Boo'); | ||
@@ -473,9 +473,9 @@ assert.instanceOf(err, Error); | ||
}); | ||
test('8.7.3 Rejecting promise does not cause Unhandled exceptions', function(done) { | ||
test('8.7.3 Rejecting promise does not cause Unhandled exceptions', function (done) { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
return new Promise(function(resolve, reject) { | ||
setTimeout(function() { | ||
function () { | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { | ||
reject(new Error('lol')); | ||
@@ -490,3 +490,3 @@ }); | ||
.create() | ||
.catch(function(err) { | ||
.catch(function (err) { | ||
assert.equal(err.message, 'lol'); | ||
@@ -500,12 +500,12 @@ }) | ||
'8.8 Resolving Value can be altered by After & Last middleware', | ||
function() { | ||
function () { | ||
let obj; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
}); | ||
test('8.8.1 After middleware can alter outcome ASYNC', function(done) { | ||
test('8.8.1 After middleware can alter outcome ASYNC', function (done) { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
function () { | ||
return 'abc'; | ||
@@ -516,6 +516,6 @@ }, | ||
obj.create.after(async function() { | ||
obj.create.after(async function () { | ||
return 'def'; | ||
}); | ||
obj.create.after(function(resolveValue) { | ||
obj.create.after(function (resolveValue) { | ||
assert.equal(resolveValue, 'def'); | ||
@@ -526,7 +526,7 @@ }); | ||
}); | ||
test('8.8.2 After middleware can alter outcome SYNC', function(done) { | ||
test('8.8.2 After middleware can alter outcome SYNC', function (done) { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
function () { | ||
return 'abc'; | ||
@@ -537,6 +537,6 @@ }, | ||
obj.create.after(function() { | ||
obj.create.after(function () { | ||
return 'def'; | ||
}); | ||
obj.create.after(function(resolveValue) { | ||
obj.create.after(function (resolveValue) { | ||
assert.equal(resolveValue, 'def'); | ||
@@ -547,7 +547,7 @@ }); | ||
}); | ||
test('8.8.3 Last middleware can alter outcome ASYNC', function(done) { | ||
test('8.8.3 Last middleware can alter outcome ASYNC', function (done) { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
function () { | ||
return 'abc'; | ||
@@ -558,6 +558,6 @@ }, | ||
obj.create.last(function() { | ||
obj.create.last(function () { | ||
return Promise.resolve('def'); | ||
}); | ||
obj.create.last(function(resolveValue) { | ||
obj.create.last(function (resolveValue) { | ||
assert.equal(resolveValue, 'def'); | ||
@@ -568,7 +568,7 @@ }); | ||
}); | ||
test('8.8.4 Last middleware can alter outcome SYNC', function(done) { | ||
test('8.8.4 Last middleware can alter outcome SYNC', function (done) { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
function () { | ||
return 'abc'; | ||
@@ -579,6 +579,6 @@ }, | ||
obj.create.last(function() { | ||
obj.create.last(function () { | ||
return 'def'; | ||
}); | ||
obj.create.last(function(resolveValue) { | ||
obj.create.last(function (resolveValue) { | ||
assert.equal(resolveValue, 'def'); | ||
@@ -585,0 +585,0 @@ }); |
@@ -7,8 +7,8 @@ /** | ||
const midd = require('../'); | ||
const midd = require('..'); | ||
suite('6. Before / After / Last Synchronous middleware', function() { | ||
setup(function() {}); | ||
suite('6. Before / After / Last Synchronous middleware', function () { | ||
setup(function () {}); | ||
teardown(function() {}); | ||
teardown(function () {}); | ||
@@ -19,3 +19,3 @@ // The numbering (e.g. 1.1.1) has nothing to do with order | ||
test('6.1 Types Test', function() { | ||
test('6.1 Types Test', function () { | ||
const obj = Object.create(null); | ||
@@ -43,3 +43,3 @@ midd.make(obj, 'create', { | ||
suite('6.2. middleware before/after Sequence of invocation', function() { | ||
suite('6.2. middleware before/after Sequence of invocation', function () { | ||
let obj; | ||
@@ -55,3 +55,3 @@ let midd1; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
@@ -69,3 +69,3 @@ midd1 = sinon.spy(); | ||
teardown(function() { | ||
teardown(function () { | ||
obj.create(); | ||
@@ -120,3 +120,3 @@ assert.ok( | ||
test('6.2.1 Multiple arguments', function() { | ||
test('6.2.1 Multiple arguments', function () { | ||
obj.create.before(midd1, midd2, midd3); | ||
@@ -126,3 +126,3 @@ obj.create.last(middFinal); | ||
}); | ||
test('6.2.2 Multiple calls', function() { | ||
test('6.2.2 Multiple calls', function () { | ||
obj.create.last(middFinal); | ||
@@ -136,3 +136,3 @@ obj.create.before(midd1); | ||
}); | ||
test('6.2.3 An array', function() { | ||
test('6.2.3 An array', function () { | ||
obj.create.before([midd1, midd2, midd3]); | ||
@@ -142,3 +142,3 @@ obj.create.last([middFinal]); | ||
}); | ||
test('6.2.4 Array mixed with arg', function() { | ||
test('6.2.4 Array mixed with arg', function () { | ||
obj.create.before([midd1, midd2], midd3); | ||
@@ -150,3 +150,3 @@ obj.create.last(middFinal); | ||
suite('6.3. middleware() argument piping', function() { | ||
suite('6.3. middleware() argument piping', function () { | ||
let obj; | ||
@@ -159,3 +159,3 @@ let mainMidd; | ||
test('6.3.1 Three arguments', function() { | ||
test('6.3.1 Three arguments', function () { | ||
obj = Object.create(null); | ||
@@ -196,6 +196,6 @@ mainMidd = sinon.spy(); | ||
}); | ||
suite('6.3.2 Main Callback return value is what is returned', function() { | ||
suite('6.3.2 Main Callback return value is what is returned', function () { | ||
function setupMiddleware(returnValue) { | ||
obj = Object.create(null); | ||
mainMidd = function() { | ||
mainMidd = function () { | ||
return returnValue; | ||
@@ -210,3 +210,3 @@ }; | ||
} | ||
test('6.3.2.2 Using a string', function() { | ||
test('6.3.2.2 Using a string', function () { | ||
setupMiddleware('value'); | ||
@@ -216,3 +216,3 @@ const val = obj.create(); | ||
}); | ||
test('6.3.2.3 Using a number', function() { | ||
test('6.3.2.3 Using a number', function () { | ||
setupMiddleware(9); | ||
@@ -225,10 +225,10 @@ const val = obj.create(); | ||
suite('6.5. Failing middleware cases', function() { | ||
suite('6.5. Failing middleware cases', function () { | ||
let obj; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
midd.make(obj, 'create', { beforeAfter: true }); | ||
}); | ||
test('6.5.1.1 Before middleware throws an error', function() { | ||
obj.create.before(function() { | ||
test('6.5.1.1 Before middleware throws an error', function () { | ||
obj.create.before(function () { | ||
throw new Error('an error'); | ||
@@ -240,4 +240,4 @@ }); | ||
test('6.5.1.1.2 After middleware throws an error', function() { | ||
obj.create.after(function() { | ||
test('6.5.1.1.2 After middleware throws an error', function () { | ||
obj.create.after(function () { | ||
throw new Error('an error'); | ||
@@ -248,3 +248,3 @@ }); | ||
test('6.5.1.2 Main callback throws an error', function() { | ||
test('6.5.1.2 Main callback throws an error', function () { | ||
const custObj = Object.create(null); | ||
@@ -254,3 +254,3 @@ midd.make( | ||
'create', | ||
function() { | ||
function () { | ||
throw new Error('an error'); | ||
@@ -264,12 +264,12 @@ }, | ||
}); | ||
suite('6.6. Return Value propagation to After middl', function() { | ||
suite('6.6. Return Value propagation to After middl', function () { | ||
let obj; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
}); | ||
test('6.6.1 Returning value from main callback gets passed as an extra argument to the after middleware', function() { | ||
test('6.6.1 Returning value from main callback gets passed as an extra argument to the after middleware', function () { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
function () { | ||
return 'abc'; | ||
@@ -280,3 +280,3 @@ }, | ||
obj.create.after(function(arg1, arg2, resolveValue) { | ||
obj.create.after(function (arg1, arg2, resolveValue) { | ||
assert.equal(resolveValue, 'abc'); | ||
@@ -291,12 +291,12 @@ }); | ||
'6.8 Returning Value can be altered by After & Last middleware', | ||
function() { | ||
function () { | ||
let obj; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
}); | ||
test('6.8.1 After middleware can alter outcome ASYNC', function() { | ||
test('6.8.1 After middleware can alter outcome ASYNC', function () { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
function () { | ||
return 'abc'; | ||
@@ -307,6 +307,6 @@ }, | ||
obj.create.after(function() { | ||
obj.create.after(function () { | ||
return 'def'; | ||
}); | ||
obj.create.after(function(returnValue) { | ||
obj.create.after(function (returnValue) { | ||
assert.equal(returnValue, 'def'); | ||
@@ -318,7 +318,7 @@ }); | ||
}); | ||
test('6.8.3 Last middleware can alter final return value', function() { | ||
test('6.8.3 Last middleware can alter final return value', function () { | ||
midd.make( | ||
obj, | ||
'create', | ||
function() { | ||
function () { | ||
return 'abc'; | ||
@@ -329,6 +329,6 @@ }, | ||
obj.create.last(function() { | ||
obj.create.last(function () { | ||
return 'def'; | ||
}); | ||
obj.create.last(function(resolveValue) { | ||
obj.create.last(function (resolveValue) { | ||
assert.equal(resolveValue, 'def'); | ||
@@ -335,0 +335,0 @@ }); |
@@ -7,6 +7,6 @@ /** | ||
const { assert } = require('chai'); | ||
const midd = require('../'); | ||
const midd = require('..'); | ||
suite('1. Basic Tests', function() { | ||
test('1.1 Types Test', function() { | ||
suite('1. Basic Tests', function () { | ||
test('1.1 Types Test', function () { | ||
const obj = Object.create(null); | ||
@@ -17,3 +17,3 @@ midd.make(obj, 'create'); | ||
}); | ||
test('1.2 Default return value', function() { | ||
test('1.2 Default return value', function () { | ||
const obj = Object.create(null); | ||
@@ -26,3 +26,3 @@ midd.make(obj, 'create'); | ||
suite('2. middleware.use() Sequence of invocation Synchronous', function() { | ||
suite('2. middleware.use() Sequence of invocation Synchronous', function () { | ||
let obj; | ||
@@ -33,3 +33,3 @@ let lastMidd; | ||
let thirdMidd; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
@@ -43,3 +43,3 @@ lastMidd = sinon.spy(); | ||
teardown(function() { | ||
teardown(function () { | ||
obj.create(); | ||
@@ -81,6 +81,6 @@ assert.ok( | ||
test('2.1 Multiple arguments', function() { | ||
test('2.1 Multiple arguments', function () { | ||
obj.create.use(firstMidd, secondMidd, thirdMidd); | ||
}); | ||
test('2.2 Multiple calls', function() { | ||
test('2.2 Multiple calls', function () { | ||
obj.create.use(firstMidd); | ||
@@ -90,6 +90,6 @@ obj.create.use(secondMidd); | ||
}); | ||
test('2.3 An array', function() { | ||
test('2.3 An array', function () { | ||
obj.create.use([firstMidd, secondMidd, thirdMidd]); | ||
}); | ||
test('2.4 Array mixed with arg', function() { | ||
test('2.4 Array mixed with arg', function () { | ||
obj.create.use([firstMidd, secondMidd], thirdMidd); | ||
@@ -99,3 +99,3 @@ }); | ||
suite('2.10 middleware.use() Sequence of invocation Asynchronous', function() { | ||
suite('2.10 middleware.use() Sequence of invocation Asynchronous', function () { | ||
let obj; | ||
@@ -111,3 +111,3 @@ let lastMidd; | ||
setup(function() { | ||
setup(function () { | ||
spyLastMidd = sinon.spy(); | ||
@@ -119,12 +119,12 @@ spyFirstMidd = sinon.spy(); | ||
obj = Object.create(null); | ||
lastMidd = async function() { | ||
lastMidd = async function () { | ||
spyLastMidd(); | ||
}; | ||
firstMidd = async function() { | ||
firstMidd = async function () { | ||
spyFirstMidd(); | ||
}; | ||
secondMidd = async function() { | ||
secondMidd = async function () { | ||
spySecondMidd(); | ||
}; | ||
thirdMidd = async function() { | ||
thirdMidd = async function () { | ||
spyThirdMidd(); | ||
@@ -136,3 +136,3 @@ }; | ||
teardown(async function() { | ||
teardown(async function () { | ||
await obj.create(); | ||
@@ -165,6 +165,6 @@ assert.ok(spyFirstMidd.calledOnce, 'firstMidd should be called only once'); | ||
test('2.10.1 Multiple arguments', function() { | ||
test('2.10.1 Multiple arguments', function () { | ||
obj.create.use(firstMidd, secondMidd, thirdMidd); | ||
}); | ||
test('2.10.2 Multiple calls', function() { | ||
test('2.10.2 Multiple calls', function () { | ||
obj.create.use(firstMidd); | ||
@@ -174,6 +174,6 @@ obj.create.use(secondMidd); | ||
}); | ||
test('2.10.3 An array', function() { | ||
test('2.10.3 An array', function () { | ||
obj.create.use([firstMidd, secondMidd, thirdMidd]); | ||
}); | ||
test('2.10.4 Array mixed with arg', function() { | ||
test('2.10.4 Array mixed with arg', function () { | ||
obj.create.use([firstMidd, secondMidd], thirdMidd); | ||
@@ -183,3 +183,3 @@ }); | ||
suite('3. middleware() argument piping', function() { | ||
suite('3. middleware() argument piping', function () { | ||
let obj; | ||
@@ -191,5 +191,5 @@ let lastMidd; | ||
teardown(function() {}); | ||
teardown(function () {}); | ||
test('3.1 Three arguments', function() { | ||
test('3.1 Three arguments', function () { | ||
function checkMiddlewareArgs(arg1, arg2, arg3) { | ||
@@ -213,3 +213,3 @@ assert.equal(arg1, 1); | ||
}); | ||
test('3.2 Mutating arguments', function() { | ||
test('3.2 Mutating arguments', function () { | ||
let count = 1; | ||
@@ -238,3 +238,3 @@ function checkMiddlewareArgs(foo, bar) { | ||
suite('4 middleware returning values should be ignored', function() { | ||
suite('4 middleware returning values should be ignored', function () { | ||
/** | ||
@@ -247,4 +247,4 @@ * Invokes the middleware. | ||
function invoke(returnValue) { | ||
const lastMidd = function() {}; | ||
const firstMidd = function() { | ||
const lastMidd = function () {}; | ||
const firstMidd = function () { | ||
return returnValue; | ||
@@ -258,46 +258,46 @@ }; | ||
} | ||
test('4.1 return undefined', function() { | ||
test('4.1 return undefined', function () { | ||
assert.isUndefined(invoke(undefined)); | ||
}); | ||
test('4.2 return null', function() { | ||
test('4.2 return null', function () { | ||
assert.isUndefined(invoke(null)); | ||
}); | ||
test('4.3 return void', function() { | ||
test('4.3 return void', function () { | ||
// eslint-disable-next-line no-void | ||
assert.isUndefined(invoke(void 0)); | ||
}); | ||
test('4.4 return boolean false', function() { | ||
test('4.4 return boolean false', function () { | ||
assert.isUndefined(invoke(false)); | ||
}); | ||
test('4.5 return boolean true', function() { | ||
test('4.5 return boolean true', function () { | ||
assert.isUndefined(invoke(true)); | ||
}); | ||
test('4.6 return empty object', function() { | ||
test('4.6 return empty object', function () { | ||
assert.isUndefined(invoke({})); | ||
}); | ||
test('4.7 return string', function() { | ||
test('4.7 return string', function () { | ||
assert.isUndefined(invoke('one')); | ||
}); | ||
test('4.8 return number', function() { | ||
test('4.8 return number', function () { | ||
assert.isUndefined(invoke(7)); | ||
}); | ||
test('4.9 return number 0', function() { | ||
test('4.9 return number 0', function () { | ||
assert.isUndefined(invoke(0)); | ||
}); | ||
test('4.10 return NaN', function() { | ||
test('4.10 return NaN', function () { | ||
// eslint-disable-next-line no-restricted-globals | ||
assert.isUndefined(invoke(NaN)); | ||
}); | ||
test('4.11 return empty Array', function() { | ||
test('4.11 return empty Array', function () { | ||
assert.isUndefined(invoke([])); | ||
}); | ||
test('4.12 return function', function() { | ||
const fn = function() {}; | ||
test('4.12 return function', function () { | ||
const fn = function () {}; | ||
assert.isUndefined(invoke(fn)); | ||
}); | ||
test('4.13 return regex', function() { | ||
test('4.13 return regex', function () { | ||
const re = /a/; | ||
assert.isUndefined(invoke(re)); | ||
}); | ||
test('4.13 return Error instance', function() { | ||
test('4.13 return Error instance', function () { | ||
const err = new Error('inst'); | ||
@@ -308,5 +308,5 @@ assert.isUndefined(invoke(err)); | ||
suite('5. Failing middleware cases', function() { | ||
suite('5. Failing middleware cases', function () { | ||
let obj; | ||
setup(function() { | ||
setup(function () { | ||
obj = Object.create(null); | ||
@@ -316,6 +316,6 @@ midd.make(obj, 'create'); | ||
test('5.1.2 middleware accepts throw error', function() { | ||
test('5.1.2 middleware accepts throw error', function () { | ||
const custObj = Object.create(null); | ||
midd.make(custObj, 'create'); | ||
custObj.create.use(function() { | ||
custObj.create.use(function () { | ||
throw new Error('an error'); | ||
@@ -331,5 +331,5 @@ }); | ||
}); | ||
test('5.1.3 main callback accepts throw error', function() { | ||
test('5.1.3 main callback accepts throw error', function () { | ||
const custObj = Object.create(null); | ||
midd.make(custObj, 'create', function() { | ||
midd.make(custObj, 'create', function () { | ||
throw new Error('an error'); | ||
@@ -345,3 +345,3 @@ }); | ||
test('5.1.4 Catch All option', function() { | ||
test('5.1.4 Catch All option', function () { | ||
const custObj = Object.create(null); | ||
@@ -351,7 +351,7 @@ midd.make( | ||
'create', | ||
function() { | ||
function () { | ||
throw new Error('an error'); | ||
}, | ||
{ | ||
catchAll: err => { | ||
catchAll: (err) => { | ||
assert.instanceOf(err, Error, '"err" should be instanceOf Error'); | ||
@@ -358,0 +358,0 @@ assert.equal(err.message, 'an error', 'Error message should match'); |
@@ -6,3 +6,3 @@ /** | ||
const midd = require('../'); | ||
const midd = require('..'); | ||
@@ -18,3 +18,3 @@ /** | ||
let middleware; | ||
setup(function() { | ||
setup(function () { | ||
middleware = Object.create(null); | ||
@@ -24,3 +24,3 @@ midd.make( | ||
'create', | ||
function() { | ||
function () { | ||
return Promise.resolve(); | ||
@@ -32,5 +32,5 @@ }, | ||
test(`7.${num}.1 accepts a promise`, function(done) { | ||
middleware.create[middMethod](function() { | ||
return new Promise(function(resolve) { | ||
test(`7.${num}.1 accepts a promise`, function (done) { | ||
middleware.create[middMethod](function () { | ||
return new Promise(function (resolve) { | ||
resolve(); | ||
@@ -42,6 +42,6 @@ }); | ||
}); | ||
test(`7.${num}.2 propagates error`, function(done) { | ||
middleware.create[middMethod](function() { | ||
return new Promise(function(resolve, reject) { | ||
setTimeout(function() { | ||
test(`7.${num}.2 propagates error`, function (done) { | ||
middleware.create[middMethod](function () { | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { | ||
reject(new Error('poop')); | ||
@@ -51,10 +51,10 @@ }); | ||
}); | ||
middleware.create().catch(function() { | ||
middleware.create().catch(function () { | ||
done(); | ||
}); | ||
}); | ||
test(`7.${num}.3 propagates error message`, function(done) { | ||
middleware.create[middMethod](function() { | ||
return new Promise(function(resolve, reject) { | ||
setTimeout(function() { | ||
test(`7.${num}.3 propagates error message`, function (done) { | ||
middleware.create[middMethod](function () { | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { | ||
reject(new Error('Error')); | ||
@@ -66,3 +66,3 @@ }); | ||
.create() | ||
.catch(function(err) { | ||
.catch(function (err) { | ||
assert.equal(err.message, 'Error'); | ||
@@ -72,5 +72,5 @@ }) | ||
}); | ||
test(`7.${num}.4 arguments propagate`, function(done) { | ||
middleware.create[middMethod](function(arg1) { | ||
return new Promise(function(resolve) { | ||
test(`7.${num}.4 arguments propagate`, function (done) { | ||
middleware.create[middMethod](function (arg1) { | ||
return new Promise(function (resolve) { | ||
assert.equal(arg1, 1); | ||
@@ -80,4 +80,4 @@ resolve(); | ||
}); | ||
middleware.create[middMethod](function(arg1) { | ||
return new Promise(function(resolve) { | ||
middleware.create[middMethod](function (arg1) { | ||
return new Promise(function (resolve) { | ||
assert.equal(arg1, 1); | ||
@@ -91,7 +91,7 @@ resolve(); | ||
test(`7.${num}.5 async resolution`, function(done) { | ||
test(`7.${num}.5 async resolution`, function (done) { | ||
let invoked = false; | ||
middleware.create[middMethod](function() { | ||
return new Promise(function(resolve) { | ||
setTimeout(function() { | ||
middleware.create[middMethod](function () { | ||
return new Promise(function (resolve) { | ||
setTimeout(function () { | ||
invoked = true; | ||
@@ -104,3 +104,3 @@ resolve(); | ||
.create() | ||
.then(function() { | ||
.then(function () { | ||
assert.ok(invoked); | ||
@@ -110,7 +110,7 @@ }) | ||
}); | ||
test(`7.${num}.6 async rejection`, function(done) { | ||
test(`7.${num}.6 async rejection`, function (done) { | ||
let invoked = false; | ||
middleware.create[middMethod](function() { | ||
return new Promise(function(resolve, reject) { | ||
setTimeout(function() { | ||
middleware.create[middMethod](function () { | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { | ||
invoked = true; | ||
@@ -123,3 +123,3 @@ reject(); | ||
.create() | ||
.then(null, function() { | ||
.then(null, function () { | ||
assert.ok(invoked); | ||
@@ -130,3 +130,3 @@ }) | ||
test(`7.${num}.7 async resolution for final callback`, function(done) { | ||
test(`7.${num}.7 async resolution for final callback`, function (done) { | ||
let invoked = false; | ||
@@ -137,5 +137,5 @@ middleware = Object.create(null); | ||
'create', | ||
function() { | ||
return new Promise(function(resolve) { | ||
setTimeout(function() { | ||
function () { | ||
return new Promise(function (resolve) { | ||
setTimeout(function () { | ||
invoked = true; | ||
@@ -150,3 +150,3 @@ resolve(); | ||
.create() | ||
.then(function() { | ||
.then(function () { | ||
assert.ok(invoked); | ||
@@ -168,13 +168,13 @@ }) | ||
suite('7. Promise Interface', function() { | ||
suite('7.1 Middleware with use()', function() { | ||
suite('7. Promise Interface', function () { | ||
suite('7.1 Middleware with use()', function () { | ||
applyTests(1, 'use', { async: true }); | ||
}); | ||
suite('7.2 Middleware with before()', function() { | ||
suite('7.2 Middleware with before()', function () { | ||
applyTests(2, 'before', { beforeAfter: true, async: true }); | ||
}); | ||
suite('7.3 Middleware with after()', function() { | ||
suite('7.3 Middleware with after()', function () { | ||
applyTests(3, 'after', { beforeAfter: true, async: true }); | ||
}); | ||
suite('7.8 Middleware with use() check', function() { | ||
suite('7.8 Middleware with use() check', function () { | ||
const newMidd = Object.create(null); | ||
@@ -184,3 +184,3 @@ midd.make( | ||
'create', | ||
function() { | ||
function () { | ||
return Promise.resolve(); | ||
@@ -191,6 +191,6 @@ }, | ||
test('7.8.3 propagates error message', function(done) { | ||
newMidd.create.use(function() { | ||
return new Promise(function(resolve, reject) { | ||
setTimeout(function() { | ||
test('7.8.3 propagates error message', function (done) { | ||
newMidd.create.use(function () { | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { | ||
reject(new Error('Error')); | ||
@@ -202,3 +202,3 @@ }); | ||
.create() | ||
.then(null, function(err) { | ||
.then(null, function (err) { | ||
assert.equal(err.message, 'Error'); | ||
@@ -205,0 +205,0 @@ done(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
59589
385
0
+ Addedasync@3.2.0(transitive)
+ Addedlodash@4.17.20(transitive)
- Removedasync@3.2.6(transitive)
- Removedlodash@4.17.21(transitive)
Updatedasync@3.2.0
Updatedlodash@4.17.20