Skip to content

Commit

Permalink
revert: sync hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Apr 28, 2021
1 parent 33d91fd commit 5fe97b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/plugins/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,14 @@ async function fireFilterHook(hook, hookList, params) {
payload => resolve(payload),
err => reject(err)
);
return;
}
if (returned) {
resolve(returned);
}
});
}

for (const hookObj of hookList) {
// eslint-disable-next-line
params = await fireMethod(hookObj, params);
Expand Down
9 changes: 7 additions & 2 deletions test/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Plugins', () => {
});
});

it('should register and fire a filter hook having 2 methods, one returning a promise, one calling the callback', async () => {
it('should register and fire a filter hook having 3 methods, one returning a promise, one calling the callback and one just returning', async () => {
function method1(data, callback) {
data.foo += 1;
callback(null, data);
Expand All @@ -58,12 +58,17 @@ describe('Plugins', () => {
resolve(data);
});
}
function method3(data) {
data.foo += 1;
return data;
}

plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method1 });
plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method2 });
plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method3 });

const data = await plugins.hooks.fire('filter:test.hook2', { foo: 1 });
assert.strictEqual(data.foo, 7);
assert.strictEqual(data.foo, 8);
});

it('should register and fire a filter hook that returns a promise that gets rejected', (done) => {
Expand Down

0 comments on commit 5fe97b9

Please sign in to comment.