From 92d26620787ec03588899bdcfdcd350b2115247f Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 14 Sep 2026 19:12:17 +0200 Subject: [PATCH] Move slowTest and externalTest to test/common.js These are used outside of the integration tests, but including the integration index file causes the very slow setup of the contorller and host. Avoid the integration setup costs when running commands such as `pnpm mocha test/lib` by moving these utility functions to the common test functions. --- test/common.js | 22 ++++++++++++++++++++++ test/host/server.js | 2 +- test/integration/clusterio.js | 3 ++- test/integration/index.js | 19 ------------------- test/integration/instance.js | 4 ++-- test/integration/link.js | 3 ++- test/integration/patch.js | 2 +- test/integration/server.js | 3 ++- test/lib/ModStore.test.js | 2 +- test/lib/external/FactorioVersions.test.js | 2 +- test/lib/external/LatestReleases.test.js | 2 +- test/lib/shared_commands.js | 2 +- test/messages/mod.test.js | 6 ++---- 13 files changed, 38 insertions(+), 34 deletions(-) diff --git a/test/common.js b/test/common.js index b35116d9..12bf426e 100644 --- a/test/common.js +++ b/test/common.js @@ -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); +} diff --git a/test/host/server.js b/test/host/server.js index b3469fce..dd4789dc 100644 --- a/test/host/server.js +++ b/test/host/server.js @@ -6,7 +6,7 @@ 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"; diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index b68f3809..01cd0681 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -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"; diff --git a/test/integration/index.js b/test/integration/index.js index 11db0d8e..48b018df 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -119,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) { diff --git a/test/integration/instance.js b/test/integration/instance.js index 8bcdec7d..e82d3bfb 100644 --- a/test/integration/instance.js +++ b/test/integration/instance.js @@ -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"; diff --git a/test/integration/link.js b/test/integration/link.js index 53b3c76b..8bfdd211 100644 --- a/test/integration/link.js +++ b/test/integration/link.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")); diff --git a/test/integration/patch.js b/test/integration/patch.js index d222ff6d..8f04302a 100644 --- a/test/integration/patch.js +++ b/test/integration/patch.js @@ -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 diff --git a/test/integration/server.js b/test/integration/server.js index f0e08c30..fe3d129b 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -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() { diff --git a/test/lib/ModStore.test.js b/test/lib/ModStore.test.js index cce56b59..4c7d1b0b 100644 --- a/test/lib/ModStore.test.js +++ b/test/lib/ModStore.test.js @@ -8,7 +8,7 @@ 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"); diff --git a/test/lib/external/FactorioVersions.test.js b/test/lib/external/FactorioVersions.test.js index f63554d9..b87d9016 100644 --- a/test/lib/external/FactorioVersions.test.js +++ b/test/lib/external/FactorioVersions.test.js @@ -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() { diff --git a/test/lib/external/LatestReleases.test.js b/test/lib/external/LatestReleases.test.js index 686b6b52..951e9376 100644 --- a/test/lib/external/LatestReleases.test.js +++ b/test/lib/external/LatestReleases.test.js @@ -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() { diff --git a/test/lib/shared_commands.js b/test/lib/shared_commands.js index d8c7dcc8..740550ad 100644 --- a/test/lib/shared_commands.js +++ b/test/lib/shared_commands.js @@ -3,7 +3,7 @@ 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"; diff --git a/test/messages/mod.test.js b/test/messages/mod.test.js index 7371665b..486a6a2a 100644 --- a/test/messages/mod.test.js +++ b/test/messages/mod.test.js @@ -2,11 +2,9 @@ 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() {