Files
factorio-clusterio/test/integration/create.js
Hornwitser 5dcaca4d0b Migrate to ECMAScript Modules
Migrate the usage of CommonJS specific code and imports to ESM.  Roughly
summarised this:
- Changes all require() calls to import statement or expressions.
- Changes usage of module.exports to export statements.
- Replaces require.resolve with import.meta.resolve.
- Replaces conditional imports with conditional subpath imports.
- Replaces module === require.main with import.meta.main.
- Adds the full filename with extention to all relative imports.
- Changes all usage of __dirname and __filename to their import.meta
  equivalents.
- Sets "type": "module" in package.json files.
- Removes usage of "use strict".
- Adds .ts an an alias of .js for the webpack build.

Due to differences in how require and import resolves files the plugin
entrypoints will have to include the filename and extension after this
migration in order to work.
2026-09-11 22:43:57 +02:00

66 lines
2.2 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs/promises";
import jwt from "jsonwebtoken";
import path from "node:path";
import events from "node:events";
import child_process from "node:child_process";
import util from "node:util";
const cwd = path.join("temp", "test_integration");
async function exec(command, options = {}) {
// Uncomment to show commands run in tests
// console.log(command);
options = { cwd, ...options };
return await util.promisify(child_process.exec)(command, options);
}
describe("Integration of create tool", function () {
beforeEach(async function () {
await fs.mkdir(cwd, { recursive: true });
});
afterEach(async function () {
await fs.rm(cwd, { recursive: true, maxRetries: 10 });
});
it("should create a new standalone installation", async function () {
this.skip();
await exec([
"node ../../packages/create",
"--mode standalone",
"--admin Danielv123",
"--http-port 8099",
"--host-name localhost",
"--public-address localhost",
"--factorio-dir test/factorio",
"--plugins --",
].join(" "));
// Check that the generated config is correct
const controllerConfig = JSON.parse(await fs.readFile(path.join(cwd, "config-controller.json")));
assert.equal(controllerConfig["controller.http_port"], 8099);
const hostConfig = JSON.parse(await fs.readFile(path.join(cwd, "config-host.json")));
assert.equal(hostConfig["host.name"], "local");
assert.equal(hostConfig["host.public_address"], "localhost");
assert.equal(hostConfig["host.factorio_directory"], "test/factorio");
assert.equal(hostConfig["host.controller_url"], "http://localhost:8099/");
}).timeout(1200000);
it("should create a new controller installation", async function () {
this.skip();
await exec([
"node ../../packages/create",
"--mode controller",
"--admin Danielv123",
"--http-port 8099",
"--public-address localhost",
"--plugins --",
].join(" "));
// Check that the generated config is correct
const controllerConfig = JSON.parse(await fs.readFile(path.join(cwd, "config-controller.json")));
assert.equal(controllerConfig["controller.http_port"], 8099);
await assert.rejects(fs.access(path.join(cwd, "config-host.json")));
}).timeout(60000);
});