mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
Nothing covered whether plugins are loaded at all, or whether the messages they declare are routed. The integration tests only loaded the first party plugins, so what coverage existed came incidentally from testing those. Add a plugin under test/file which exists purely to be loaded by the tests. It is plain JavaScript rather than TypeScript so that it needs no build step, which the plugin loader is happy with as it requires the entry point and reads the version from package.json like any other plugin. Covered so far: the plugin loads on the controller and on the host, its title and version are reported, the command it adds is available in clusterioctl, a request from control reaches the controller, a request from control reaches a host, and an event sent with broadcastEventToHosts arrives at the hosts. Left for a follow up, as all three need a running instance: a request to an instance, a Lua module reached over rcon, and log statements being tagged with the plugin and host or instance id. Part of #342, and a step towards #721 as core no longer needs a first party plugin to have the plugin system under test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
27 lines
712 B
JavaScript
27 lines
712 B
JavaScript
"use strict";
|
|
const { Command, CommandTree } = require("@clusterio/lib");
|
|
const { BaseCtlPlugin } = require("@clusterio/ctl");
|
|
|
|
const testPluginCommands = new CommandTree({
|
|
name: "test-plugin", description: "Test plugin commands",
|
|
});
|
|
testPluginCommands.add(new Command({
|
|
definition: ["echo <message>", "Print the message given to it", (yargs) => {
|
|
yargs.positional("message", { describe: "message to print", type: "string" });
|
|
}],
|
|
handler: async function(args, control) {
|
|
// eslint-disable-next-line no-console
|
|
console.log(args.message);
|
|
},
|
|
}));
|
|
|
|
class CtlPlugin extends BaseCtlPlugin {
|
|
async addCommands(rootCommand) {
|
|
rootCommand.add(testPluginCommands);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
CtlPlugin,
|
|
};
|