Merge remote-tracking branch 'origin/master' into fix/headless-export-icons

This commit is contained in:
Danielv123 committed 2026-11-01 18:32:20 +01:00
commit 46fd7fcad4
114 files changed
+5338 -1165

No files matched your search

+41 -12
View File
@@ -3,7 +3,7 @@ import path from "node:path";
import { FactorioServer } from "@clusterio/host/dist/node/src/server.js";
import {
_exportLocale, _loadLayeredIcon, _loadSimpleIcon, _warnMissingBuiltinIcons,
_createSheetState, _exportIcons, _exportLocale, _loadLayeredIcon, _loadSimpleIcon, _warnMissingBuiltinIcons,
} from "@clusterio/host/dist/node/src/export.js";
@@ -14,7 +14,25 @@ describe("host/src/export", function() {
testServer = await FactorioServer.fromOptions(path.join("test", "file", "factorio"), writePath, {});
});
let warnings;
let originalLogger;
beforeEach(function() {
warnings = [];
originalLogger = testServer._logger;
testServer._logger = Object.create(originalLogger, { warn: { value: message => warnings.push(message) } });
});
afterEach(function() {
testServer._logger = originalLogger;
});
describe("exportLocale()", function() {
it("warns about mods without a zip and exports the rest", async function() {
const locale = await _exportLocale(
testServer, new Map([["missing_mod", "1.0.0"]]), new Map(), ["base", "missing_mod"], "en"
);
assert.equal(locale.size > 0, true);
assert.deepEqual(warnings, ["Skipping locale of missing_mod, its mod zip was not found"]);
});
it("returns a flattened mapping with locale definitions", async function() {
let locale = await _exportLocale(testServer, new Map(), new Map(), ["base"], "en");
assert.deepEqual(locale, new Map([
@@ -32,6 +50,28 @@ describe("host/src/export", function() {
// test-icon.png is a red 64px icon followed by a blue 32px mipmap
const red = 0xff0000ff;
describe("exportIcons()", function() {
it("skips icons that fail to load and exports the rest", async function() {
const state = await _createSheetState();
const icon = "__base__/graphics/icons/test-icon.png";
const prototypes = [
{ type: "item", name: "first", icon, icon_size: 64 },
{ type: "item", name: "no-layers", icons: [] },
{ type: "item", name: "unknown-mod", icon: "__not-a-mod__/graphics/icons/x.png", icon_size: 64 },
{ type: "item", name: "last", icon, icon_size: 64 },
];
const count = await _exportIcons(testServer, new Map(), { zipCache: new Map() }, prototypes, "item", state);
assert.equal(count, 2);
assert.deepEqual(
state.metadata.item.map(entry => [entry.name, Boolean(entry.icon)]),
[["first", true], ["no-layers", false], ["unknown-mod", false], ["last", true]],
);
assert.equal(warnings.length, 2);
assert.match(warnings[0], /^Skipping icon of item no-layers: /);
assert.match(warnings[1], /^Skipping icon of item unknown-mod: Got path for unknown mod not-a-mod/);
});
});
// Stands in for the data dir of a full install
const graphicsDataDir = path.join("test", "file", "factorio-graphics");
describe("loadSimpleIcon()", function() {
@@ -82,17 +122,6 @@ describe("host/src/export", function() {
});
});
describe("warnMissingBuiltinIcons()", function() {
let warnings;
let logger;
beforeEach(function() {
warnings = [];
logger = testServer._logger;
testServer._logger = { warn: msg => warnings.push(msg) };
});
afterEach(function() {
testServer._logger = logger;
});
it("warns once with the number of missing builtin files", function() {
_warnMissingBuiltinIcons(testServer, { zipCache: new Map() }, new Map([
["__base__/graphics/icons/a.png", null],