Add and fix tests

This commit is contained in:
Cooldude2606 committed 2024-11-13 22:17:27 +00:00
1 parent 81444cc447
commit 3850558d49
8 files changed
+60 -15

No files matched your search

+3
View File
@@ -41,6 +41,7 @@ Many thanks to the following for contributing to this release:
- Changed default role selection to be a dropdown menu rather than id [#664](https://github.com/clusterio/clusterio/pull/664).
- Added credential option to config entries to allow writing sensitive data that can't be read back remotely.
- Allow hidden and readonly graphical representations of config values. [#665](https://github.com/clusterio/clusterio/pull/665).
- Added locale exporting for all builtin mods, not just for the base mod. [#684](https://github.com/clusterio/clusterio/pull/684).
### Changes
@@ -70,6 +71,8 @@ Many thanks to the following for contributing to this release:
- Updated display name and description of `controller.external_address` to avoid confusion. [#674](https://github.com/clusterio/clusterio/pull/674)
- Fixed invalid transient state during server start. [#676](https://github.com/clusterio/clusterio/issues/676)
- Fixed host user sync to instances after reconnecting to the controller. [#678](https://github.com/clusterio/clusterio/pull/678)
- Fixed WebUI adding and displaying the wrong base mod version. [#684](https://github.com/clusterio/clusterio/pull/684).
- Fixed WebUI inconsistent pattern matching for factorio version. [#684](https://github.com/clusterio/clusterio/pull/684).
### Breaking Changes
+1 -3
View File
@@ -620,11 +620,9 @@ export default class Host extends lib.Link {
async fetchMods(mods: Iterable<lib.ModRecord>) {
// This is better than the previous hard coded names
// But it really shouldn't be a hard coded version either
const builtinModNames = lib.ModPack.getBuiltinMods("2.0").map(builtinMod => builtinMod.name);
const builtinModNames = lib.ModPack.getBuiltinModNames("2.0");
const modInfos: Promise<lib.ModInfo>[] = [];
for (const mod of mods) {
// XXX These mods ship with Factorio, but the list of mods may
// change and should not be hardcoded here.
if (builtinModNames.includes(mod.name)) {
continue;
}
+10 -7
View File
@@ -103,8 +103,8 @@ async function loadFile(server: FactorioServer, modVersions: Map<string, string>
let [, mod, filePath] = match;
const builtinMods = lib.ModPack.getBuiltinMods(server.version!);
if (builtinMods.some(builtinMod => builtinMod.name === mod)) {
const builtinModNames = ["core", ...lib.ModPack.getBuiltinModNames(server.version!)];
if (builtinModNames.includes(mod)) {
try {
return await fs.readFile(server.dataPath(mod, filePath));
} catch (err: any) {
@@ -397,15 +397,18 @@ async function exportLocale(
}
}
const builtinMods = lib.ModPack.getBuiltinMods(server.version!);
for (const builtinMod of builtinMods) {
const localeFilePath = server.dataPath(builtinMod.name, "locale", languageCode, `${builtinMod.name}.cfg`);
const builtinModNames = [
// Filter if on builtin mods so "core" does not need to be specified in modOrder
"core", ...lib.ModPack.getBuiltinModNames(server.version!).filter(mod => modOrder.includes(mod)),
];
for (const builtinModName of builtinModNames) {
const localeFilePath = server.dataPath(builtinModName, "locale", languageCode, `${builtinModName}.cfg`);
mergeLocale(lib.parse(await fs.readFile(localeFilePath, "utf8")));
}
const builtinModNames = ["export", ...builtinMods.map(builtinMod => builtinMod.name)];
const builtinModNamesExport = ["export", ...builtinModNames];
for (let mod of modOrder) {
if (builtinModNames.includes(mod)) {
if (builtinModNamesExport.includes(mod)) {
continue;
}
+2 -2
View File
@@ -346,9 +346,9 @@ function reorderDependencies(modules: SaveModule[]) {
const knownScenarios: Record<string, lib.ModuleInfo> = {
// First seen in 0.17.63
"4e866186ebe297f1038fd325b09df1a1f5e2fdd1": new lib.ModuleInfo("freeplay", "0.17.63", [], ["scenario"]),
// First seen in 1.2.0 (aka 2.0) TODO Uncomment once clusterio lib supports 2.0
// First seen in 2.0 TODO Uncomment once clusterio lib supports 2.0
// The rest of the code has already been updated to support the new control.lua file for 2.0
// "bcbdde18ce4ec16ebfd93bd694cd9b12ef969c9a": new lib.ModuleInfo("freeplay", "1.2.0", [], ["scenario"]),
// "bcbdde18ce4ec16ebfd93bd694cd9b12ef969c9a": new lib.ModuleInfo("freeplay", "2.0.0", [], ["scenario"]),
};
/**
+5
View File
@@ -391,6 +391,7 @@ export default class ModPack {
*/
static getBuiltinMods(factorioVersion: string) {
let defaultMods: ModRecord[] = [
// "core" not included because core cannot be disabled
{ name: "base", enabled: true, version: factorioVersion },
];
@@ -405,4 +406,8 @@ export default class ModPack {
return defaultMods;
}
static getBuiltinModNames(factorioVersion: string) {
return this.getBuiltinMods(factorioVersion).map(builtinMod => builtinMod.name);
}
}
@@ -1,4 +1,4 @@
; Test data for exportLocale
[test]
key-a=1
key-b=2
base-a=1
base-b=2
+10 -1
View File
@@ -17,7 +17,16 @@ describe("host/src/export", function() {
it("returns a flattened mapping with locale definitions", async function() {
let locale = await _exportLocale(testServer, new Map(), ["base"], "en");
assert.deepEqual(locale, new Map([["test.key-a", "1"], ["test.key-b", "2"]]));
assert.deepEqual(locale, new Map([
["test.core-a", "1"], ["test.core-b", "2"],
["test.base-a", "1"], ["test.base-b", "2"],
]));
});
it("returns a filtered locale definitions based on mod order", async function() {
let locale = await _exportLocale(testServer, new Map(), [], "en");
assert.deepEqual(locale, new Map([
["test.core-a", "1"], ["test.core-b", "2"],
]));
});
});
});
+27
View File
@@ -378,5 +378,32 @@ describe("lib/data/ModPack", function() {
/* eslint-enable indent */
});
});
describe("getBuiltinMods()", function() {
it("should work with versions before 2.0", function() {
const builtinMods = ModPack.getBuiltinMods("1.1");
assert.deepEqual(builtinMods, [
{ name: "base", enabled: true, version: "1.1" },
]);
});
it("should work with versions after 2.0", function() {
const builtinMods = ModPack.getBuiltinMods("2.0");
assert.deepEqual(builtinMods, [
{ name: "base", enabled: true, version: "2.0" },
{ name: "elevated-rails", enabled: false, version: "2.0" },
{ name: "quality", enabled: false, version: "2.0" },
{ name: "space-age", enabled: false, version: "2.0" },
]);
});
});
describe("getBuiltinModNames()", function() {
it("should work with versions before 2.0", function() {
const builtinModNames = ModPack.getBuiltinModNames("1.1");
assert.deepEqual(builtinModNames, ["base"]);
});
it("should work with versions after 2.0", function() {
const builtinModNames = ModPack.getBuiltinModNames("2.0");
assert.deepEqual(builtinModNames, ["base", "elevated-rails", "quality", "space-age"]);
});
});
});
});