Files
factorio-clusterio/test/integration/export.js
T
HornwitserandHornwitser 94692dc418 Fix tests failing due broken Factorio detection (#839)
* Fix tests failing due to missmatched Factorio detection

When the configured factorio directory is full of junk then the tests
use the first directory it finds for one of its tests, while the server
code uses a more elaborate logic to figure this out.

Turns out this is complicating things more than needed. Simply trying
each entry in the directory and seeing if it works when treated as a
directory always work, regardsless of symlinks, junctions,
reparse-points or whatever else filesystem magic there is.

* Skip tests requiring Factorio if it's not present

Prevent confusing test failures by skipping all the tests that require a
working Factorio installation to sucteed, and print a warning at the end
of the test suite if tests may have been skipped due to this.

* Handle ENOTDIR when determining Factorio version

If the path to the factorio install contains a component that is not a
file then ENOTDIR may be returned on POSIX like systems.  Treat this the
same as ENOENT so that detection logic works when used on a file.

---------

Co-authored-by: Hornwitser <code@hornwitser.no>
2026-03-01 23:06:03 +00:00

39 lines
1.3 KiB
JavaScript

"use strict";
const assert = require("assert").strict;
const path = require("path");
const { _exportLocale } = require("@clusterio/host/dist/node/src/export");
const { FactorioServer } = require("@clusterio/host/dist/node/src/server");
const { factorioDir, requiresFactorio } = require("./index");
describe("Integration of lib/factorio/export", function() {
describe("exportLocale()", function() {
requiresFactorio(this);
it("returns a nested Map with base game locale information", async function() {
let writePath = path.join("temp", "test", "server");
let testServer = new FactorioServer(factorioDir, writePath, {});
await testServer.init();
let locale = await _exportLocale(testServer, new Map(), ["base"], "en");
assert(locale instanceof Map, "locale is not a map");
assert.equal(locale.get("entity-name.fish"), "Fish");
assert.equal(locale.get("entity-name.small-lamp"), "Lamp");
let empty_keys = 0;
for (let [key, value] of locale) {
// key is always a string
assert.equal(typeof key, "string");
// Value is always a string, nearly always truthy
if (!value) {
empty_keys += 1;
}
assert.equal(typeof value, "string");
}
assert(empty_keys < 10, `Got unusually high amount (${empty_keys}) of empty keys`);
});
});
});