Invoke plugin hooks via common function

Use a common function to iterate through and invoke the given hook in
every plugin, and ignore errors thrown by plugins from these hooks.
This commit is contained in:
Hornwitser committed 2020-05-30 14:27:59 +02:00
1 parent 01ea301a8c
commit fc3686b865
4 files changed
+71 -50

No files matched your search

+27
View File
@@ -119,4 +119,31 @@ describe("lib/plugin", function() {
);
});
});
describe("invokeHook()", function() {
let betaTestCalled = false;
let plugins = new Map([
["alpha", {
test: async function() { },
pass: async function(arg) { return arg; },
error: async function() { throw new Error("Test"); },
}],
["beta", {
test: async function() { betaTestCalled = true; },
pass: async function() { },
error: async function() { },
}],
]);
it("should invoke the hook on the plugin", async function() {
await plugin.invokeHook(plugins, "test");
assert(betaTestCalled, "Hook was not called");
});
it("should pass and return args", async function() {
let result = await plugin.invokeHook(plugins, "pass", 1234);
assert.deepEqual(result, [1234]);
});
it("should ignore errors", async function() {
await plugin.invokeHook(plugins, "error");
});
});
});