diff --git a/test/integration/export.js b/test/integration/export.js index a0d8345a..94648233 100644 --- a/test/integration/export.js +++ b/test/integration/export.js @@ -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"); diff --git a/test/integration/index.js b/test/integration/index.js index c2081cf9..62e14af9 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -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, diff --git a/test/integration/server.js b/test/integration/server.js index 9073bbb8..02d088cf 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -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() {