mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +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.
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
import * as lib from "@clusterio/lib";
|
|
import assert from "node:assert/strict";
|
|
|
|
// Each migration test should indicate which version introduced the migration
|
|
|
|
describe("lib/config/definitions/migrations", function() {
|
|
describe("Controller Config", function() {
|
|
it("should migrate 'external_address' to 'public_url'", function() { // Alpha 19
|
|
const config = lib.ControllerConfig.fromJSON({
|
|
"controller.external_address": "https://example.com:4000",
|
|
}, "controller");
|
|
|
|
assert.equal(config.get("controller.public_url"), "https://example.com:4000",
|
|
"public_url contains the wrong value");
|
|
assert.equal(config.fields["controller.external_address"], undefined,
|
|
"external_address was not removed");
|
|
});
|
|
});
|
|
describe("Host Config", function() {
|
|
|
|
});
|
|
describe("Instance Config", function() {
|
|
it("should migrate boolean sync to string enum", function() { // Alpha 19
|
|
const configTrue = lib.InstanceConfig.fromJSON({
|
|
"factorio.sync_adminlist": true,
|
|
"factorio.sync_whitelist": true,
|
|
"factorio.sync_banlist": true,
|
|
}, "controller");
|
|
|
|
assert.equal(configTrue.get("factorio.sync_adminlist"), "enabled", "sync_adminlist contains wrong value");
|
|
assert.equal(configTrue.get("factorio.sync_whitelist"), "enabled", "sync_adminlist contains wrong value");
|
|
assert.equal(configTrue.get("factorio.sync_banlist"), "enabled", "sync_adminlist contains wrong value");
|
|
|
|
const configFalse = lib.InstanceConfig.fromJSON({
|
|
"factorio.sync_adminlist": false,
|
|
"factorio.sync_whitelist": false,
|
|
"factorio.sync_banlist": false,
|
|
}, "controller");
|
|
|
|
assert.equal(configFalse.get("factorio.sync_adminlist"), "disabled", "sync_adminlist contains wrong value");
|
|
assert.equal(configFalse.get("factorio.sync_whitelist"), "disabled", "sync_adminlist contains wrong value");
|
|
assert.equal(configFalse.get("factorio.sync_banlist"), "disabled", "sync_adminlist contains wrong value");
|
|
});
|
|
});
|
|
describe("Control Config", function() {
|
|
|
|
});
|
|
});
|