Cleanup
This commit is contained in:
7
node_modules/kareem/CHANGELOG.md
generated
vendored
7
node_modules/kareem/CHANGELOG.md
generated
vendored
@@ -1,6 +1,9 @@
|
||||
# Change Log
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
<a name="2.3.2"></a>
|
||||
## 2.3.2 (2020-12-08)
|
||||
|
||||
* fix: handle sync errors in pre hooks if there are multiple hooks
|
||||
|
||||
<a name="2.3.0"></a>
|
||||
## 2.3.0 (2018-09-24)
|
||||
|
||||
524
node_modules/kareem/README.md
generated
vendored
524
node_modules/kareem/README.md
generated
vendored
@@ -24,11 +24,9 @@ appropriate, giving you more fine-grained control over your function hooks.
|
||||
#### It runs without any hooks specified
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
#### It runs basic serial pre hooks
|
||||
@@ -38,44 +36,38 @@ when your pre hook is finished.
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
var count = 0;
|
||||
var count = 0;
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count;
|
||||
done();
|
||||
});
|
||||
hooks.pre('cook', function(done) {
|
||||
++count;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count);
|
||||
});
|
||||
```
|
||||
|
||||
#### It can run multipe pre hooks
|
||||
|
||||
```javascript
|
||||
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count1;
|
||||
done();
|
||||
});
|
||||
hooks.pre('cook', function(done) {
|
||||
++count1;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count2;
|
||||
done();
|
||||
});
|
||||
hooks.pre('cook', function(done) {
|
||||
++count2;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
});
|
||||
```
|
||||
|
||||
#### It can run fully synchronous pre hooks
|
||||
@@ -85,25 +77,22 @@ fully synchronous.
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
++count1;
|
||||
});
|
||||
hooks.pre('cook', function() {
|
||||
++count1;
|
||||
});
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
++count2;
|
||||
});
|
||||
hooks.pre('cook', function() {
|
||||
++count2;
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(error) {
|
||||
assert.equal(null, error);
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(error) {
|
||||
assert.equal(null, error);
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
});
|
||||
```
|
||||
|
||||
#### It properly attaches context to pre hooks
|
||||
@@ -112,27 +101,24 @@ Pre save hook functions are bound to the second parameter to `execPre()`
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
this.bacon = 3;
|
||||
done();
|
||||
});
|
||||
hooks.pre('cook', function(done) {
|
||||
this.bacon = 3;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
this.eggs = 4;
|
||||
done();
|
||||
});
|
||||
hooks.pre('cook', function(done) {
|
||||
this.eggs = 4;
|
||||
done();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
// In the pre hooks, `this` will refer to `obj`
|
||||
hooks.execPre('cook', obj, function(error) {
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
done();
|
||||
});
|
||||
|
||||
// In the pre hooks, `this` will refer to `obj`
|
||||
hooks.execPre('cook', obj, function(error) {
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
});
|
||||
```
|
||||
|
||||
#### It can execute parallel (async) pre hooks
|
||||
@@ -144,38 +130,35 @@ async pre hooks have called `done()`.
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
hooks.execPre('cook', obj, function() {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', obj, function() {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
});
|
||||
```
|
||||
|
||||
#### It supports returning a promise
|
||||
@@ -186,148 +169,162 @@ next middleware.
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
this.bacon = 3;
|
||||
resolve();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
hooks.pre('cook', function() {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
this.bacon = 3;
|
||||
resolve();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
var obj = { bacon: 0 };
|
||||
var obj = { bacon: 0 };
|
||||
|
||||
hooks.execPre('cook', obj, function() {
|
||||
assert.equal(3, obj.bacon);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', obj, function() {
|
||||
assert.equal(3, obj.bacon);
|
||||
});
|
||||
```
|
||||
|
||||
## post hooks
|
||||
|
||||
acquit:ignore:end
|
||||
|
||||
#### It runs without any hooks specified
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.execPost('cook', null, [1], function(error, eggs) {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1], function(error, eggs) {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
done();
|
||||
});
|
||||
```
|
||||
|
||||
#### It executes with parameters passed in
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.post('cook', function(eggs, bacon, callback) {
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
callback();
|
||||
});
|
||||
hooks.post('cook', function(eggs, bacon, callback) {
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
callback();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1, 2], function(error, eggs, bacon) {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1, 2], function(error, eggs, bacon) {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
});
|
||||
```
|
||||
|
||||
#### It can use synchronous post hooks
|
||||
|
||||
```javascript
|
||||
|
||||
var execed = {};
|
||||
var execed = {};
|
||||
|
||||
hooks.post('cook', function(eggs, bacon) {
|
||||
execed.first = true;
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
});
|
||||
hooks.post('cook', function(eggs, bacon) {
|
||||
execed.first = true;
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
});
|
||||
|
||||
hooks.post('cook', function(eggs, bacon, callback) {
|
||||
execed.second = true;
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
callback();
|
||||
});
|
||||
hooks.post('cook', function(eggs, bacon, callback) {
|
||||
execed.second = true;
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
callback();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1, 2], function(error, eggs, bacon) {
|
||||
assert.ifError(error);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1, 2], function(error, eggs, bacon) {
|
||||
assert.ifError(error);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
});
|
||||
```
|
||||
|
||||
#### It supports returning a promise
|
||||
|
||||
You can also return a promise from your post hooks instead of calling
|
||||
`next()`. When the returned promise resolves, kareem will kick off the
|
||||
next middleware.
|
||||
|
||||
|
||||
```javascript
|
||||
hooks.post('cook', function(bacon) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
this.bacon = 3;
|
||||
resolve();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
var obj = { bacon: 0 };
|
||||
|
||||
hooks.execPost('cook', obj, obj, function() {
|
||||
assert.equal(obj.bacon, 3);
|
||||
});
|
||||
```
|
||||
|
||||
## wrap()
|
||||
|
||||
acquit:ignore:end
|
||||
|
||||
#### It wraps pre and post calls into one call
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [obj];
|
||||
args.push(function(error, result) {
|
||||
assert.ifError(error);
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
var args = [obj];
|
||||
args.push(function(error, result) {
|
||||
assert.ifError(error);
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
|
||||
assert.equal(obj, result);
|
||||
done();
|
||||
});
|
||||
assert.equal(obj, result);
|
||||
});
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
callback(null, o);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
callback(null, o);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
```
|
||||
|
||||
## createWrapper()
|
||||
@@ -335,73 +332,70 @@ next middleware.
|
||||
#### It wraps wrap() into a callable function
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var cook = hooks.createWrapper(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
callback(null, o);
|
||||
},
|
||||
obj);
|
||||
var cook = hooks.createWrapper(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
callback(null, o);
|
||||
},
|
||||
obj);
|
||||
|
||||
cook(obj, function(error, result) {
|
||||
assert.ifError(error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
cook(obj, function(error, result) {
|
||||
assert.ifError(error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
|
||||
assert.equal(obj, result);
|
||||
done();
|
||||
});
|
||||
|
||||
assert.equal(obj, result);
|
||||
});
|
||||
```
|
||||
|
||||
## clone()
|
||||
|
||||
acquit:ignore:end
|
||||
|
||||
#### It clones a Kareem object
|
||||
|
||||
```javascript
|
||||
|
||||
var k1 = new Kareem();
|
||||
k1.pre('cook', function() {});
|
||||
k1.post('cook', function() {});
|
||||
var k1 = new Kareem();
|
||||
k1.pre('cook', function() {});
|
||||
k1.post('cook', function() {});
|
||||
|
||||
var k2 = k1.clone();
|
||||
assert.deepEqual(['cook'], Object.keys(k2._pres));
|
||||
assert.deepEqual(['cook'], Object.keys(k2._posts));
|
||||
|
||||
var k2 = k1.clone();
|
||||
assert.deepEqual(Array.from(k2._pres.keys()), ['cook']);
|
||||
assert.deepEqual(Array.from(k2._posts.keys()), ['cook']);
|
||||
```
|
||||
|
||||
## merge()
|
||||
@@ -409,20 +403,18 @@ next middleware.
|
||||
#### It pulls hooks from another Kareem object
|
||||
|
||||
```javascript
|
||||
|
||||
var k1 = new Kareem();
|
||||
var test1 = function() {};
|
||||
k1.pre('cook', test1);
|
||||
k1.post('cook', function() {});
|
||||
var k1 = new Kareem();
|
||||
var test1 = function() {};
|
||||
k1.pre('cook', test1);
|
||||
k1.post('cook', function() {});
|
||||
|
||||
var k2 = new Kareem();
|
||||
var test2 = function() {};
|
||||
k2.pre('cook', test2);
|
||||
var k3 = k2.merge(k1);
|
||||
assert.equal(k3._pres['cook'].length, 2);
|
||||
assert.equal(k3._pres['cook'][0].fn, test2);
|
||||
assert.equal(k3._pres['cook'][1].fn, test1);
|
||||
assert.equal(k3._posts['cook'].length, 1);
|
||||
|
||||
var k2 = new Kareem();
|
||||
var test2 = function() {};
|
||||
k2.pre('cook', test2);
|
||||
var k3 = k2.merge(k1);
|
||||
assert.equal(k3._pres.get('cook').length, 2);
|
||||
assert.equal(k3._pres.get('cook')[0].fn, test2);
|
||||
assert.equal(k3._pres.get('cook')[1].fn, test1);
|
||||
assert.equal(k3._posts.get('cook').length, 1);
|
||||
```
|
||||
|
||||
|
||||
4
node_modules/kareem/docs.js
generated
vendored
4
node_modules/kareem/docs.js
generated
vendored
@@ -1,5 +1,7 @@
|
||||
var acquit = require('acquit');
|
||||
|
||||
require('acquit-ignore')();
|
||||
|
||||
var content = require('fs').readFileSync('./test/examples.test.js').toString();
|
||||
var blocks = acquit.parse(content);
|
||||
|
||||
@@ -29,7 +31,7 @@ for (var i = 0; i < blocks.length; ++i) {
|
||||
acquit.trimEachLine(it.comments[0]) + '\n\n' :
|
||||
'';
|
||||
mdOutput += '```javascript\n';
|
||||
mdOutput += ' ' + it.code + '\n';
|
||||
mdOutput += it.code + '\n';
|
||||
mdOutput += '```\n\n';
|
||||
}
|
||||
}
|
||||
|
||||
9
node_modules/kareem/index.js
generated
vendored
9
node_modules/kareem/index.js
generated
vendored
@@ -57,12 +57,13 @@ Kareem.prototype.execPre = function(name, context, args, callback) {
|
||||
|
||||
callMiddlewareFunction(pre.fn, context, args, args[0]);
|
||||
} else {
|
||||
let error = null;
|
||||
let maybePromise = null;
|
||||
try {
|
||||
maybePromise = pre.fn.call(context);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
if (err != null) {
|
||||
return callback(err);
|
||||
}
|
||||
}
|
||||
|
||||
if (isPromise(maybePromise)) {
|
||||
@@ -74,11 +75,11 @@ Kareem.prototype.execPre = function(name, context, args, callback) {
|
||||
return;
|
||||
} else {
|
||||
return process.nextTick(function() {
|
||||
callback(error);
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
next(error);
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
13
node_modules/kareem/package.json
generated
vendored
13
node_modules/kareem/package.json
generated
vendored
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kareem",
|
||||
"version": "2.3.1",
|
||||
"version": "2.3.2",
|
||||
"description": "Next-generation take on pre/post function hooks",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -12,14 +12,11 @@
|
||||
"url": "git://github.com/vkarpov15/kareem.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acquit": "1.x",
|
||||
"acquit-ignore": "0.1.x",
|
||||
"nyc": "11.x",
|
||||
"mocha": "5.x",
|
||||
"standard-version": "4.4.0"
|
||||
"mocha": "5.x"
|
||||
},
|
||||
"author": "Valeri Karpov <val@karpov.io>",
|
||||
"license": "Apache-2.0"
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.1.tgz"
|
||||
,"_integrity": "sha512-l3hLhffs9zqoDe8zjmb/mAN4B8VT3L56EUvKNqLFVs9YlFA+zx7ke1DO8STAdDyYNkeSo1nKmjuvQeI12So8Xw=="
|
||||
,"_from": "kareem@2.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
47
node_modules/kareem/test/examples.test.js
generated
vendored
47
node_modules/kareem/test/examples.test.js
generated
vendored
@@ -17,7 +17,10 @@ describe('pre hooks', function() {
|
||||
|
||||
it('runs without any hooks specified', function(done) {
|
||||
hooks.execPre('cook', null, function() {
|
||||
// ...
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,7 +37,9 @@ describe('pre hooks', function() {
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,7 +60,9 @@ describe('pre hooks', function() {
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
|
||||
@@ -78,7 +85,9 @@ describe('pre hooks', function() {
|
||||
assert.equal(null, error);
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
|
||||
@@ -102,7 +111,9 @@ describe('pre hooks', function() {
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
|
||||
@@ -140,7 +151,9 @@ describe('pre hooks', function() {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
|
||||
@@ -162,7 +175,9 @@ describe('pre hooks', function() {
|
||||
|
||||
hooks.execPre('cook', obj, function() {
|
||||
assert.equal(3, obj.bacon);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -193,7 +208,9 @@ describe('post hooks', function() {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
|
||||
@@ -220,7 +237,33 @@ describe('post hooks', function() {
|
||||
assert.ok(execed.second);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
|
||||
/* You can also return a promise from your post hooks instead of calling
|
||||
* `next()`. When the returned promise resolves, kareem will kick off the
|
||||
* next middleware.
|
||||
*/
|
||||
it('supports returning a promise', function(done) {
|
||||
hooks.post('cook', function(bacon) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
this.bacon = 3;
|
||||
resolve();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
var obj = { bacon: 0 };
|
||||
|
||||
hooks.execPost('cook', obj, obj, function() {
|
||||
assert.equal(obj.bacon, 3);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -271,7 +314,9 @@ describe('wrap()', function() {
|
||||
assert.equal('no', obj.tofu);
|
||||
|
||||
assert.equal(obj, result);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
|
||||
hooks.wrap(
|
||||
@@ -343,7 +388,9 @@ describe('createWrapper()', function() {
|
||||
assert.equal('no', obj.tofu);
|
||||
|
||||
assert.equal(obj, result);
|
||||
// acquit:ignore:start
|
||||
done();
|
||||
// acquit:ignore:end
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
20
node_modules/kareem/test/pre.test.js
generated
vendored
20
node_modules/kareem/test/pre.test.js
generated
vendored
@@ -287,6 +287,26 @@ describe('execPre', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles sync errors in pre if there are more hooks', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
execed.first = true;
|
||||
throw new Error('Oops!');
|
||||
});
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
execed.second = true;
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(err) {
|
||||
assert.ok(err);
|
||||
assert.ok(execed.first);
|
||||
assert.equal(err.message, 'Oops!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('execPreSync', function() {
|
||||
|
||||
Reference in New Issue
Block a user