mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 23:04:52 +09:00
29 files changed
+83
-45
No files matched your search
@@ -33,3 +33,25 @@ export function testRoundTripJsonSerialisable(Class, tests) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mark that this test takes a lot of time, or depends on a test that takes a
|
||||
* lot of time.
|
||||
*/
|
||||
export function slowTest(test) {
|
||||
if (process.env.FAST_TEST) {
|
||||
test.skip();
|
||||
}
|
||||
test.timeout(30000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark that this test depends on an external API and may be slow or flaky.
|
||||
*/
|
||||
export function externalTest(test) {
|
||||
if (process.env.NO_EXTERNAL_TEST) {
|
||||
test.skip();
|
||||
}
|
||||
test.timeout(60000);
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
addPluginConfigFields,
|
||||
} from "@clusterio/lib";
|
||||
|
||||
import "../setup_logging.js";
|
||||
|
||||
class MockEvent {}
|
||||
|
||||
class MockInstanceConfig extends EventEmitter {
|
||||
|
||||
@@ -7,6 +7,8 @@ import { wait, expositionContentType } from "@clusterio/lib";
|
||||
import * as routes from "@clusterio/controller/dist/node/src/routes.js";
|
||||
import * as mock from "../mock.js";
|
||||
|
||||
import "../setup_logging.js";
|
||||
|
||||
describe("controller/src/routes", function() {
|
||||
let controller;
|
||||
let server;
|
||||
|
||||
@@ -6,8 +6,9 @@ import * as lib from "@clusterio/lib";
|
||||
import Host, { _discoverInstances } from "@clusterio/host/dist/node/src/Host.js";
|
||||
import Instance from "@clusterio/host/dist/node/src/Instance.js";
|
||||
import { HostConnector } from "@clusterio/host/dist/node/host.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
describe("Host testing", function() {
|
||||
describe("host/src/Host", function() {
|
||||
describe("discoverInstances()", function() {
|
||||
it("should discover test instance", async function() {
|
||||
const instancePath = path.join("test", "file", "instances");
|
||||
@@ -6,6 +6,8 @@ import { PlayerStats, wait } from "@clusterio/lib";
|
||||
import Instance from "@clusterio/host/dist/node/src/Instance.js";
|
||||
import { MockConnector, MockLogger, MockServer } from "../mock.js";
|
||||
|
||||
import "../setup_logging.js";
|
||||
|
||||
const addr = lib.Address.fromShorthand;
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -6,7 +6,8 @@ import path from "node:path";
|
||||
import * as hostServer from "@clusterio/host/dist/node/src/server.js";
|
||||
import { Link, wait } from "@clusterio/lib";
|
||||
import { testLines } from "../lib/factorio/lines.js";
|
||||
import { slowTest, externalTest } from "../integration/index.js";
|
||||
import { slowTest, externalTest } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
|
||||
describe("host/server", function() {
|
||||
|
||||
@@ -10,11 +10,12 @@ import * as libBuildMod from "@clusterio/lib/build_mod.js";
|
||||
|
||||
import * as testStrings from "../lib/factorio/test_strings.js";
|
||||
import {
|
||||
TestControl, TestControlConnector, url, controlToken, slowTest,
|
||||
TestControl, TestControlConnector, url, controlToken,
|
||||
execCtl, execCtlProcess, execController, execHost, sendRcon, getControl,
|
||||
spawnNode, instancesDir, factorioDir, databaseDir, controllerConfigPath,
|
||||
requiresFactorio, hasFactorio,
|
||||
} from "./index.js";
|
||||
import { slowTest } from "../common.js";
|
||||
import { ControllerEcho, HostEchoReceived } from "../file/test_plugin/messages.js";
|
||||
|
||||
|
||||
|
||||
@@ -8,11 +8,13 @@ import util from "node:util";
|
||||
import events from "node:events";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { LineSplitter, ConsoleTransport, logger } from "@clusterio/lib";
|
||||
import { LineSplitter, logger } from "@clusterio/lib";
|
||||
|
||||
import { selectTargetCommand, initialize as initializeCtl } from "@clusterio/ctl";
|
||||
import { _listFactorioVersions } from "@clusterio/host/dist/node/src/server.js";
|
||||
|
||||
import "../setup_logging.js";
|
||||
|
||||
// Make sure permissions from plugins are loaded
|
||||
import "../../plugins/global_chat/dist/node/index.js";
|
||||
import "../../plugins/player_auth/dist/node/index.js";
|
||||
@@ -117,25 +119,6 @@ export class TestHostConnector extends lib.WebSocketClientConnector {
|
||||
}
|
||||
}
|
||||
|
||||
// Mark that this test takes a lot of time, or depends on a test that takes a lot of time.
|
||||
export function slowTest(test) {
|
||||
|
||||
if (process.env.FAST_TEST) {
|
||||
test.skip();
|
||||
}
|
||||
|
||||
test.timeout(30000);
|
||||
}
|
||||
|
||||
// Mark that this test depends on an external API and may be slow or flaky.
|
||||
export function externalTest(test) {
|
||||
if (process.env.NO_EXTERNAL_TEST) {
|
||||
test.skip();
|
||||
}
|
||||
|
||||
test.timeout(60000);
|
||||
}
|
||||
|
||||
// Mark that this test or suite of tests requires a factorio install to run.
|
||||
export function requiresFactorio(testOrSuite) {
|
||||
if (testOrSuite.skip) {
|
||||
@@ -316,13 +299,6 @@ before(async function() {
|
||||
console.log("SILENT_TEST is present in env, loggers after bootstrap will be muted.");
|
||||
}
|
||||
|
||||
// Some integration tests may cause log events
|
||||
logger.add(new ConsoleTransport({
|
||||
level: "info",
|
||||
format: new lib.TerminalFormat(),
|
||||
filter: () => !silent,
|
||||
}));
|
||||
|
||||
// If fast test is enabled then output that it is
|
||||
|
||||
if (process.env.FAST_TEST) {
|
||||
|
||||
@@ -3,9 +3,9 @@ import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
import { testMatrix } from "../common.js";
|
||||
import { slowTest, testMatrix } from "../common.js";
|
||||
import {
|
||||
slowTest, exec, execCtl, execCtlProcess, sendRcon, getControl,
|
||||
execCtl, execCtlProcess, sendRcon, getControl,
|
||||
requiresFactorio, hasFactorio, instancesDir,
|
||||
} from "./index.js";
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@ import events from "node:events";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
import {
|
||||
TestControlConnector, TestHostConnector, TestControl, get, exec, url, controlToken, slowTest,
|
||||
TestControlConnector, TestHostConnector, TestControl, url, controlToken,
|
||||
} from "./index.js";
|
||||
import { ConnectionClosed, ProtocolError, PolicyViolation, AuthenticationFailed } from "@clusterio/lib";
|
||||
import { slowTest } from "../common.js";
|
||||
|
||||
let tokenHost = jwt.sign({ aud: "host", host: 0 }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import path from "node:path";
|
||||
import { patch, SaveModule } from "@clusterio/host/dist/node/src/patch.js";
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
import { slowTest } from "./index.js";
|
||||
import { slowTest } from "../common.js";
|
||||
|
||||
|
||||
// The server integration test is required to run before this one
|
||||
|
||||
@@ -8,7 +8,8 @@ import { InstanceManager } from "@clusterio/controller";
|
||||
import { FactorioServer, _getFactorioVersion } from "@clusterio/host/dist/node/src/server.js";
|
||||
import { logger } from "@clusterio/lib";
|
||||
|
||||
import { slowTest, factorioDir, requiresFactorio } from "./index.js";
|
||||
import { factorioDir, requiresFactorio } from "./index.js";
|
||||
import { slowTest } from "../common.js";
|
||||
|
||||
|
||||
describe("Integration of host/src/server", function() {
|
||||
|
||||
@@ -8,7 +8,8 @@ import JSZip from "jszip"; // Added for creating mock zips
|
||||
const nativeFetch = global.fetch;
|
||||
|
||||
import { ModStore, ModInfo, ModVersionEquality } from "@clusterio/lib"; // Adjust path based on compiled output
|
||||
import { externalTest } from "../integration/index.js";
|
||||
import { externalTest } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
const MODS_DIR = path.join("temp", "test", "mod_store", "mods");
|
||||
const CACHE_FILE = path.join(MODS_DIR, "mod-info-cache.json");
|
||||
|
||||
Vendored
+2
@@ -4,6 +4,8 @@ import path from "node:path";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
import "../setup_logging.js";
|
||||
|
||||
describe("lib/bootstrap", function() {
|
||||
describe("loadConfigFromArgs()", function() {
|
||||
const folder = path.join("temp", "test", "bootstrap");
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import "../setup_logging.js";
|
||||
|
||||
class MockDatastoreProvider extends lib.DatastoreProvider {
|
||||
constructor() {
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { fetchFactorioVersions } from "@clusterio/lib";
|
||||
import { slowTest, externalTest } from "../../integration/index.js";
|
||||
import { slowTest, externalTest } from "../../common.js";
|
||||
|
||||
describe("FactorioVersions", function() {
|
||||
describe("fetchFactorioVersions", function() {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { fetchLatestReleases, resolveReleaseChannel } from "@clusterio/lib";
|
||||
import { slowTest, externalTest } from "../../integration/index.js";
|
||||
import { slowTest, externalTest } from "../../common.js";
|
||||
|
||||
describe("LatestReleases", function() {
|
||||
describe("fetchLatestReleases", function() {
|
||||
|
||||
@@ -122,7 +122,8 @@ describe("lib/file_ops", function() {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
writes.push(lib.safeOutputFile(target, `write ${i}`, "utf8"));
|
||||
}
|
||||
await Promise.all(writes);
|
||||
// Ignore errors from concurrently renaming onto the same file.
|
||||
await Promise.allSettled(writes);
|
||||
await assertNoTemporary(target);
|
||||
assert.match(await fs.readFile(target, "utf8"), /^write \d+$/);
|
||||
});
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import assert from "node:assert/strict";
|
||||
import events from "node:events";
|
||||
|
||||
import * as mock from "../../mock.js";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as mock from "../../mock.js";
|
||||
import "../../setup_logging.js";
|
||||
|
||||
|
||||
describe("lib/link/connectors", function() {
|
||||
|
||||
@@ -3,6 +3,7 @@ import events from "node:events";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as mock from "../../mock.js";
|
||||
import "../../setup_logging.js";
|
||||
|
||||
const addr = lib.Address.fromShorthand;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
|
||||
import { testLines } from "./factorio/lines.js";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import "../setup_logging.js";
|
||||
|
||||
|
||||
describe("lib/logging_utils.js", function() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import "../setup_logging.js";
|
||||
|
||||
describe("rce_ops", function() {
|
||||
describe("updatePackage", function() {
|
||||
|
||||
@@ -3,7 +3,8 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { slowTest } from "../integration/index.js";
|
||||
import { slowTest } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
|
||||
describe("lib/shared_commands", function() {
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { MockController, MockConnector, MockControl } from "../mock.js";
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
const addr = lib.Address.fromShorthand;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as lib from "@clusterio/lib";
|
||||
|
||||
import { Controller, ControlConnection } from "@clusterio/controller";
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
describe("messages/controller", function() {
|
||||
/** @type {Controller} */
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as lib from "@clusterio/lib";
|
||||
|
||||
import { Host } from "@clusterio/host";
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
describe("messages/host", function() {
|
||||
/** @type {Host} */
|
||||
|
||||
@@ -2,11 +2,10 @@ import assert from "node:assert/strict";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { ModDependencyResolveRequest, ModDependency, ModInfo } from "@clusterio/lib";
|
||||
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||
|
||||
import { Controller, ControlConnection } from "@clusterio/controller";
|
||||
import { externalTest } from "../integration/index.js";
|
||||
|
||||
import { externalTest, testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
describe("messages/mod", function() {
|
||||
/** @type {Controller} */
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as lib from "@clusterio/lib";
|
||||
import { Controller, ControlConnection } from "@clusterio/controller";
|
||||
import { Host } from "@clusterio/host";
|
||||
|
||||
import "../setup_logging.js";
|
||||
|
||||
describe("messages/plugin", function() {
|
||||
/** @type {Host} */
|
||||
let host;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ConsoleTransport, TerminalFormat, logger } from "@clusterio/lib";
|
||||
|
||||
// Some integration tests may cause log events, import this file for such tests
|
||||
// to avoid getting the "Attempt to write logs with no transports" warning when
|
||||
// running tests individually.
|
||||
|
||||
before(function() {
|
||||
const silent = process.env.SILENT_TEST;
|
||||
|
||||
logger.add(new ConsoleTransport({
|
||||
level: "info",
|
||||
format: new TerminalFormat(),
|
||||
filter: () => !silent,
|
||||
}));
|
||||
});
|
||||
Reference in new issue
Block a user