This commit is contained in:
Jonasz Bigda
2023-03-25 21:51:42 +01:00
parent 0db1d5117e
commit b332e9ceb0
1044 changed files with 37502 additions and 63938 deletions

View File

@@ -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
View File

@@ -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() {