mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Move BaseControllerPlugin to controller/src/BaseControllerPlugin.ts Move BaseInstancePlugin to host/src/BaseInstancePlugin.ts Move BaseControlPlugin to ctl/src/BaseCtlPlugin.ts Move BaseWebPlugin to web_ui/src/BaseWebPlugin.ts This solves the circular package dependency problem of the base plugins needing types that are available only in the dependencies to lib.
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
"use strict";
|
|
const assert = require("assert").strict;
|
|
|
|
const mock = require("../mock");
|
|
const lib = require("@clusterio/lib");
|
|
|
|
|
|
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"); },
|
|
logger: new mock.MockLogger(),
|
|
}],
|
|
["beta", {
|
|
test: async function() { betaTestCalled = true; },
|
|
pass: async function() { },
|
|
error: async function() { },
|
|
logger: new mock.MockLogger(),
|
|
}],
|
|
]);
|
|
it("should invoke the hook on the plugin", async function() {
|
|
await lib.invokeHook(plugins, "test");
|
|
assert(betaTestCalled, "Hook was not called");
|
|
});
|
|
it("should pass and return args", async function() {
|
|
let result = await lib.invokeHook(plugins, "pass", 1234);
|
|
assert.deepEqual(result, [1234]);
|
|
});
|
|
it("should ignore errors", async function() {
|
|
await lib.invokeHook(plugins, "error");
|
|
});
|
|
});
|
|
});
|