mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 23:04:52 +09:00
Migrate the usage of CommonJS specific code and imports to ESM. Roughly summarised this: - Changes all require() calls to import statement or expressions. - Changes usage of module.exports to export statements. - Replaces require.resolve with import.meta.resolve. - Replaces conditional imports with conditional subpath imports. - Replaces module === require.main with import.meta.main. - Adds the full filename with extention to all relative imports. - Changes all usage of __dirname and __filename to their import.meta equivalents. - Sets "type": "module" in package.json files. - Removes usage of "use strict". - Adds .ts an an alias of .js for the webpack build. Due to differences in how require and import resolves files the plugin entrypoints will have to include the filename and extension after this migration in order to work.
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
describe("rce_ops", function() {
|
|
describe("updatePackage", function() {
|
|
it("runs", async function() {
|
|
// In dev env no side effects occur, so best we can do is check it doesn't error
|
|
await lib.updatePackage("foo");
|
|
});
|
|
});
|
|
|
|
describe("installPackage", function() {
|
|
it("runs", async function() {
|
|
// In dev env no side effects occur, so best we can do is check it doesn't error
|
|
await lib.installPackage("foo");
|
|
});
|
|
});
|
|
|
|
describe("handlePluginUpdate", function() {
|
|
it("runs", async function() {
|
|
await lib.handlePluginUpdate("foo", [{ npmPackage: "foo" }]);
|
|
});
|
|
it("rejects when plugin not installed", async function() {
|
|
await assert.rejects(
|
|
lib.handlePluginUpdate("foo", []),
|
|
/Plugin foo is not installed on this machine/
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("handlePluginInstall", function() {
|
|
const _fetch = global.fetch;
|
|
before(function() {
|
|
global.fetch = function() { return { ok: false }; };
|
|
});
|
|
after(function() {
|
|
global.fetch = _fetch;
|
|
});
|
|
|
|
it("runs", async function() {
|
|
let calledWith = "";
|
|
global.fetch = function(url) {
|
|
calledWith = url;
|
|
return { ok: true };
|
|
};
|
|
|
|
await lib.handlePluginInstall("foo");
|
|
assert.equal(calledWith, "https://registry.npmjs.com/foo");
|
|
});
|
|
it("rejects when name too long", async function() {
|
|
const pluginName = "a".repeat(215);
|
|
await assert.rejects(
|
|
lib.handlePluginInstall(pluginName),
|
|
{ message: `Invalid plugin name: ${pluginName}` }
|
|
);
|
|
});
|
|
it("rejects when invalid symbol present", async function() {
|
|
const pluginName = "?";
|
|
await assert.rejects(
|
|
lib.handlePluginInstall(pluginName),
|
|
{ message: `Invalid plugin name: ${pluginName}` },
|
|
);
|
|
});
|
|
it("rejects unregistered packages", async function() {
|
|
let calledWith = "";
|
|
global.fetch = function(url) {
|
|
calledWith = url;
|
|
return { ok: false };
|
|
};
|
|
|
|
await assert.rejects(lib.handlePluginInstall("foo"), /Unknown plugin: foo/);
|
|
assert.equal(calledWith, "https://registry.npmjs.com/foo");
|
|
});
|
|
});
|
|
});
|