mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 15:04:52 +09:00
Source factorio dir from config-host.json in tests
If a factorio dir is configured in config-host.json then use that in the tests. This removes the requirement of having a factorio installation in ./factorio or linking to one there when running the tests.
This commit is contained in:
1 parent
f3150a9261
commit
5d97e8e816
3 files changed
+30
-5
No files matched your search
@@ -5,12 +5,14 @@ const path = require("path");
|
||||
const { _exportLocale } = require("@clusterio/host/dist/node/src/export");
|
||||
const { FactorioServer } = require("@clusterio/host/dist/node/src/server");
|
||||
|
||||
const { factorioDir } = require("./index");
|
||||
|
||||
|
||||
describe("Integration of lib/factorio/export", function() {
|
||||
describe("exportLocale()", function() {
|
||||
it("returns a nested Map with base game locale information", async function() {
|
||||
let writePath = path.join("temp", "test", "server");
|
||||
let testServer = new FactorioServer("factorio", writePath, {});
|
||||
let testServer = new FactorioServer(factorioDir, writePath, {});
|
||||
await testServer.init();
|
||||
|
||||
let locale = await _exportLocale(testServer, new Map(), ["base"], "en");
|
||||
|
||||
@@ -126,15 +126,35 @@ async function get(urlPath) {
|
||||
return res;
|
||||
}
|
||||
|
||||
function loadJSON(filePath) {
|
||||
try {
|
||||
// eslint-disable-next-line node/no-sync
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
} catch (err) {
|
||||
if (err.code === "ENOENT") {
|
||||
return undefined;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
function getFactorioDir(hostConfig) {
|
||||
const factorioDir = hostConfig?.["host.factorio_directory"] ?? "factorio";
|
||||
return path.join(factorioDir);
|
||||
}
|
||||
|
||||
let controllerProcess;
|
||||
let hostProcess;
|
||||
let control;
|
||||
|
||||
const baseHostConfig = loadJSON("config-host.json");
|
||||
|
||||
let url = "https://localhost:4443/";
|
||||
let controlToken = jwt.sign({ aud: "user", user: "test" }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
let instancesDir = path.join("temp", "test", "instances");
|
||||
let modsDir = path.join("temp", "test", "mods");
|
||||
let databaseDir = path.join("temp", "test", "database");
|
||||
let factorioDir = getFactorioDir(baseHostConfig);
|
||||
let pluginListPath = path.join("temp", "test", "plugin-list.json");
|
||||
let controllerConfigPath = path.join("temp", "test", "config-controller.json");
|
||||
let hostConfigPath = path.join("temp", "test", "config-host.json");
|
||||
@@ -274,7 +294,9 @@ before(async function() {
|
||||
controllerProcess = await spawn("controller:", "node ../../packages/controller run", /Started controller/);
|
||||
|
||||
await execCtl("host create-config --id 4 --name host --generate-token");
|
||||
await exec(`node ../../packages/host config set host.factorio_directory ${path.join("..", "..", "factorio")}`);
|
||||
|
||||
const relativeFactorioDir = path.isAbsolute(factorioDir) ? factorioDir : path.join("..", "..", factorioDir);
|
||||
await exec(`node ../../packages/host config set host.factorio_directory ${relativeFactorioDir}`);
|
||||
await exec("node ../../packages/host config set host.tls_ca ../../test/file/tls/cert.pem");
|
||||
|
||||
hostProcess = await spawn("host:", "node ../../packages/host run", /Started host/);
|
||||
@@ -338,6 +360,7 @@ module.exports = {
|
||||
instancesDir,
|
||||
modsDir,
|
||||
databaseDir,
|
||||
factorioDir,
|
||||
controllerConfigPath,
|
||||
hostConfigPath,
|
||||
controlConfigPath,
|
||||
|
||||
@@ -8,13 +8,13 @@ const lib = require("@clusterio/lib");
|
||||
const { FactorioServer, _getVersion } = require("@clusterio/host/dist/node/src/server");
|
||||
const { logger } = lib;
|
||||
|
||||
const { slowTest } = require("./index");
|
||||
const { slowTest, factorioDir } = require("./index");
|
||||
|
||||
|
||||
describe("Integration of host/src/server", function() {
|
||||
describe("_getVersion()", function() {
|
||||
it("should get a version from factorio's changelog.txt", async function() {
|
||||
let version = await _getVersion(path.join("factorio", "data", "changelog.txt"));
|
||||
let version = await _getVersion(path.join(factorioDir, "data", "changelog.txt"));
|
||||
if (!/^\d+\.\d+\.\d+$/.test(version)) {
|
||||
assert.fail(`Detected version '${version}' does not followed the format x.y.z`);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ describe("Integration of host/src/server", function() {
|
||||
|
||||
describe("class FactorioServer", function() {
|
||||
let writePath = path.join("temp", "test", "integration");
|
||||
let server = new FactorioServer("factorio", writePath, {});
|
||||
let server = new FactorioServer(factorioDir, writePath, {});
|
||||
let logFile;
|
||||
|
||||
before(async function() {
|
||||
|
||||
Reference in new issue
Block a user