factorio-test-cli 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +3 -3
- package/package.json +7 -7
- package/run.js +38 -14
package/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from "commander";
|
|
3
3
|
import "./run.js";
|
|
4
|
-
program
|
|
4
|
+
await program
|
|
5
5
|
.name("factorio-test")
|
|
6
6
|
.description("cli for factorio testing")
|
|
7
|
-
.
|
|
7
|
+
.helpCommand(true)
|
|
8
8
|
.showHelpAfterError()
|
|
9
9
|
.showSuggestionAfterError()
|
|
10
|
-
.
|
|
10
|
+
.parseAsync();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "factorio-test-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A CLI to run FactorioTest.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/GlassBricks/FactorioTest",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"*.js"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"chalk": "^5.
|
|
19
|
-
"commander": "^
|
|
20
|
-
"factoriomod-debug": "^
|
|
18
|
+
"chalk": "^5.3.0",
|
|
19
|
+
"commander": "^12.1.0",
|
|
20
|
+
"factoriomod-debug": "^2.0.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@commander-js/extra-typings": "^
|
|
24
|
-
"del-cli": "^
|
|
25
|
-
"typescript": "^5.
|
|
23
|
+
"@commander-js/extra-typings": "^12.1.0",
|
|
24
|
+
"del-cli": "^6.0.0",
|
|
25
|
+
"typescript": "^5.7.2"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "npm run clean && tsc",
|
package/run.js
CHANGED
|
@@ -3,20 +3,24 @@ import * as os from "os";
|
|
|
3
3
|
import * as fsp from "fs/promises";
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
|
-
import { spawn } from "child_process";
|
|
6
|
+
import { spawn, spawnSync } from "child_process";
|
|
7
7
|
import BufferLineSplitter from "./buffer-line-splitter.js";
|
|
8
8
|
import chalk from "chalk";
|
|
9
|
+
import * as process from "node:process";
|
|
9
10
|
const thisCommand = program
|
|
10
11
|
.command("run")
|
|
11
12
|
.summary("Runs tests with Factorio test.")
|
|
12
13
|
.description("Runs tests for the specified mod with Factorio test. Exits with code 0 only if all tests pass.\n")
|
|
13
|
-
.argument("[mod-path]", "The path to the mod
|
|
14
|
-
.option("--mod-name <name>", "The name of the mod to test.
|
|
15
|
-
.option("--factorio-path <path>", "The path to the factorio binary. If not specified,
|
|
16
|
-
.option("-d --data-directory <path>", 'The path to the data directory. The "config.ini" file and the "mods" folder will be in this directory.', "./factorio-test-data")
|
|
17
|
-
.option("--
|
|
18
|
-
|
|
19
|
-
.
|
|
14
|
+
.argument("[mod-path]", "The path to the mod (folder containing info.json). A symlink will be created in the mods folder to this folder. Either this or --mod-name must be specified.")
|
|
15
|
+
.option("--mod-name <name>", "The name of the mod to test. To use this option, the mod must already be present in the mods directory (see --data-directory). Either this or [mod-path] must be specified.")
|
|
16
|
+
.option("--factorio-path <path>", "The path to the factorio binary. If not specified, attempts to auto-detect the path.")
|
|
17
|
+
.option("-d --data-directory <path>", 'The path to the factorio data directory that the testing instance will use. The "config.ini" file and the "mods" folder will be in this directory.', "./factorio-test-data-dir")
|
|
18
|
+
.option("--mods <mods...>", 'Adjust mods. By default, only the mod to test and "factorio-test" are enabled, and all others are disabled! ' +
|
|
19
|
+
'Same format as "fmtk mods adjust". Example: "--mods mod1 mod2=1.2.3" will enable mod1 any version, and mod2 version 1.2.3.')
|
|
20
|
+
.option("--show-output", "Print test output to stdout.", true)
|
|
21
|
+
.option("-v --verbose", "Enables more logging, and pipes the Factorio process output to stdout.")
|
|
22
|
+
.addHelpText("after", 'Arguments after "--" are passed to the Factorio process.')
|
|
23
|
+
.addHelpText("after", 'Suggested factorio arguments: "--cache-sprite-atlas", "--disable-audio"')
|
|
20
24
|
.action((modPath, options) => runTests(modPath, options));
|
|
21
25
|
async function runTests(modPath, options) {
|
|
22
26
|
if (modPath !== undefined && options.modName !== undefined) {
|
|
@@ -31,9 +35,14 @@ async function runTests(modPath, options) {
|
|
|
31
35
|
await fsp.mkdir(modsDir, { recursive: true });
|
|
32
36
|
const modToTest = await configureModToTest(modsDir, modPath, options.modName);
|
|
33
37
|
await installFactorioTest(modsDir);
|
|
38
|
+
const enableModsOptions = [
|
|
39
|
+
"factorio-test=true",
|
|
40
|
+
`${modToTest}=true`,
|
|
41
|
+
...(options.mods?.map((m) => (m.includes("=") ? m : `${m}=true`)) ?? []),
|
|
42
|
+
];
|
|
34
43
|
if (options.verbose)
|
|
35
|
-
console.log("
|
|
36
|
-
await runScript("fmtk mods adjust", "--modsPath", modsDir, "
|
|
44
|
+
console.log("Adjusting mods");
|
|
45
|
+
await runScript("fmtk mods adjust", "--modsPath", modsDir, "--disableExtra", ...enableModsOptions);
|
|
37
46
|
await ensureConfigIni(dataDir);
|
|
38
47
|
await setSettingsForAutorun(factorioPath, dataDir, modsDir, modToTest);
|
|
39
48
|
let resultMessage;
|
|
@@ -131,6 +140,14 @@ write-data=${dataDir}
|
|
|
131
140
|
locale=
|
|
132
141
|
`);
|
|
133
142
|
}
|
|
143
|
+
else {
|
|
144
|
+
// edit "^write-data=.*" to be dataDir
|
|
145
|
+
const content = await fsp.readFile(filePath, "utf8");
|
|
146
|
+
const newContent = content.replace(/^write-data=.*$/m, `write-data=${dataDir}`);
|
|
147
|
+
if (content !== newContent) {
|
|
148
|
+
await fsp.writeFile(filePath, newContent);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
134
151
|
}
|
|
135
152
|
async function setSettingsForAutorun(factorioPath, dataDir, modsDir, modToTest) {
|
|
136
153
|
// touch modsDir/mod-settings.dat
|
|
@@ -157,6 +174,7 @@ async function runFactorioTests(factorioPath, dataDir) {
|
|
|
157
174
|
const actualArgs = [
|
|
158
175
|
"--load-scenario",
|
|
159
176
|
"factorio-test/Test",
|
|
177
|
+
"--disable-migration-window",
|
|
160
178
|
"--mod-directory",
|
|
161
179
|
path.join(dataDir, "mods"),
|
|
162
180
|
"-c",
|
|
@@ -201,12 +219,12 @@ async function runFactorioTests(factorioPath, dataDir) {
|
|
|
201
219
|
}
|
|
202
220
|
});
|
|
203
221
|
await new Promise((resolve, reject) => {
|
|
204
|
-
factorioProcess.on("exit", (code) => {
|
|
205
|
-
if (code === 0
|
|
222
|
+
factorioProcess.on("exit", (code, signal) => {
|
|
223
|
+
if (code === 0 && resultMessage !== undefined) {
|
|
206
224
|
resolve();
|
|
207
225
|
}
|
|
208
226
|
else {
|
|
209
|
-
reject(new Error(`Factorio exited with code ${code}`));
|
|
227
|
+
reject(new Error(`Factorio exited with code ${code}, signal ${signal}`));
|
|
210
228
|
}
|
|
211
229
|
});
|
|
212
230
|
});
|
|
@@ -235,12 +253,18 @@ function runProcess(inheritStdio, command, ...args) {
|
|
|
235
253
|
});
|
|
236
254
|
});
|
|
237
255
|
}
|
|
256
|
+
function factorioIsInPath() {
|
|
257
|
+
const result = spawnSync("factorio", ["--version"], { stdio: "ignore" });
|
|
258
|
+
return result.status === 0;
|
|
259
|
+
}
|
|
238
260
|
function autoDetectFactorioPath() {
|
|
261
|
+
if (factorioIsInPath()) {
|
|
262
|
+
return "factorio";
|
|
263
|
+
}
|
|
239
264
|
let pathsToTry;
|
|
240
265
|
// check if is linux
|
|
241
266
|
if (os.platform() === "linux" || os.platform() === "darwin") {
|
|
242
267
|
pathsToTry = [
|
|
243
|
-
"factorio",
|
|
244
268
|
"~/.local/share/Steam/steamapps/common/Factorio/bin/x64/factorio",
|
|
245
269
|
"~/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app/Contents/MacOS/factorio",
|
|
246
270
|
"~/.factorio/bin/x64/factorio",
|