mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Setup logging transport in tests
Without a transport Winston will print annoying "Attempt to write logs with no transports" warnings all over the place. Setup a transport in tests that cause logging to suppress this.
This commit is contained in:
1 parent
2c52c265cf
commit
ea1cb67502
20 files changed
+42
-9
No files matched your search
@@ -12,6 +12,8 @@ import {
|
|||||||
addPluginConfigFields,
|
addPluginConfigFields,
|
||||||
} from "@clusterio/lib";
|
} from "@clusterio/lib";
|
||||||
|
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
class MockEvent {}
|
class MockEvent {}
|
||||||
|
|
||||||
class MockInstanceConfig extends EventEmitter {
|
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 routes from "@clusterio/controller/dist/node/src/routes.js";
|
||||||
import * as mock from "../mock.js";
|
import * as mock from "../mock.js";
|
||||||
|
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
describe("controller/src/routes", function() {
|
describe("controller/src/routes", function() {
|
||||||
let controller;
|
let controller;
|
||||||
let server;
|
let server;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
import Host, { _discoverInstances } from "@clusterio/host/dist/node/src/Host.js";
|
import Host, { _discoverInstances } from "@clusterio/host/dist/node/src/Host.js";
|
||||||
import Instance from "@clusterio/host/dist/node/src/Instance.js";
|
import Instance from "@clusterio/host/dist/node/src/Instance.js";
|
||||||
import { HostConnector } from "@clusterio/host/dist/node/host.js";
|
import { HostConnector } from "@clusterio/host/dist/node/host.js";
|
||||||
|
import "./setup_logging.js";
|
||||||
|
|
||||||
describe("Host testing", function() {
|
describe("Host testing", function() {
|
||||||
describe("discoverInstances()", function() {
|
describe("discoverInstances()", function() {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { PlayerStats, wait } from "@clusterio/lib";
|
|||||||
import Instance from "@clusterio/host/dist/node/src/Instance.js";
|
import Instance from "@clusterio/host/dist/node/src/Instance.js";
|
||||||
import { MockConnector, MockLogger, MockServer } from "../mock.js";
|
import { MockConnector, MockLogger, MockServer } from "../mock.js";
|
||||||
|
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
const addr = lib.Address.fromShorthand;
|
const addr = lib.Address.fromShorthand;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import * as hostServer from "@clusterio/host/dist/node/src/server.js";
|
|||||||
import { Link, wait } from "@clusterio/lib";
|
import { Link, wait } from "@clusterio/lib";
|
||||||
import { testLines } from "../lib/factorio/lines.js";
|
import { testLines } from "../lib/factorio/lines.js";
|
||||||
import { slowTest, externalTest } from "../integration/index.js";
|
import { slowTest, externalTest } from "../integration/index.js";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
|
|
||||||
describe("host/server", function() {
|
describe("host/server", function() {
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ import util from "node:util";
|
|||||||
import events from "node:events";
|
import events from "node:events";
|
||||||
|
|
||||||
import * as lib from "@clusterio/lib";
|
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 { selectTargetCommand, initialize as initializeCtl } from "@clusterio/ctl";
|
||||||
import { _listFactorioVersions } from "@clusterio/host/dist/node/src/server.js";
|
import { _listFactorioVersions } from "@clusterio/host/dist/node/src/server.js";
|
||||||
|
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
// Make sure permissions from plugins are loaded
|
// Make sure permissions from plugins are loaded
|
||||||
import "../../plugins/global_chat/dist/node/index.js";
|
import "../../plugins/global_chat/dist/node/index.js";
|
||||||
import "../../plugins/player_auth/dist/node/index.js";
|
import "../../plugins/player_auth/dist/node/index.js";
|
||||||
@@ -316,13 +318,6 @@ before(async function() {
|
|||||||
console.log("SILENT_TEST is present in env, loggers after bootstrap will be muted.");
|
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 fast test is enabled then output that it is
|
||||||
|
|
||||||
if (process.env.FAST_TEST) {
|
if (process.env.FAST_TEST) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const nativeFetch = global.fetch;
|
|||||||
|
|
||||||
import { ModStore, ModInfo, ModVersionEquality } from "@clusterio/lib"; // Adjust path based on compiled output
|
import { ModStore, ModInfo, ModVersionEquality } from "@clusterio/lib"; // Adjust path based on compiled output
|
||||||
import { externalTest } from "../integration/index.js";
|
import { externalTest } from "../integration/index.js";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
const MODS_DIR = path.join("temp", "test", "mod_store", "mods");
|
const MODS_DIR = path.join("temp", "test", "mod_store", "mods");
|
||||||
const CACHE_FILE = path.join(MODS_DIR, "mod-info-cache.json");
|
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 * as lib from "@clusterio/lib";
|
||||||
|
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
describe("lib/bootstrap", function() {
|
describe("lib/bootstrap", function() {
|
||||||
describe("loadConfigFromArgs()", function() {
|
describe("loadConfigFromArgs()", function() {
|
||||||
const folder = path.join("temp", "test", "bootstrap");
|
const folder = path.join("temp", "test", "bootstrap");
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
|||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
class MockDatastoreProvider extends lib.DatastoreProvider {
|
class MockDatastoreProvider extends lib.DatastoreProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import events from "node:events";
|
import events from "node:events";
|
||||||
|
|
||||||
import * as mock from "../../mock.js";
|
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
|
import * as mock from "../../mock.js";
|
||||||
|
import "../../setup_logging.js";
|
||||||
|
|
||||||
|
|
||||||
describe("lib/link/connectors", function() {
|
describe("lib/link/connectors", function() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import events from "node:events";
|
|||||||
|
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import * as mock from "../../mock.js";
|
import * as mock from "../../mock.js";
|
||||||
|
import "../../setup_logging.js";
|
||||||
|
|
||||||
const addr = lib.Address.fromShorthand;
|
const addr = lib.Address.fromShorthand;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import path from "node:path";
|
|||||||
|
|
||||||
import { testLines } from "./factorio/lines.js";
|
import { testLines } from "./factorio/lines.js";
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
|
|
||||||
describe("lib/logging_utils.js", function() {
|
describe("lib/logging_utils.js", function() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
describe("rce_ops", function() {
|
describe("rce_ops", function() {
|
||||||
describe("updatePackage", function() {
|
describe("updatePackage", function() {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import path from "node:path";
|
|||||||
|
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import { slowTest } from "../integration/index.js";
|
import { slowTest } from "../integration/index.js";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
|
|
||||||
describe("lib/shared_commands", function() {
|
describe("lib/shared_commands", function() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
|||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import { MockController, MockConnector, MockControl } from "../mock.js";
|
import { MockController, MockConnector, MockControl } from "../mock.js";
|
||||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
const addr = lib.Address.fromShorthand;
|
const addr = lib.Address.fromShorthand;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
|
|
||||||
import { Controller, ControlConnection } from "@clusterio/controller";
|
import { Controller, ControlConnection } from "@clusterio/controller";
|
||||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
describe("messages/controller", function() {
|
describe("messages/controller", function() {
|
||||||
/** @type {Controller} */
|
/** @type {Controller} */
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
|
|
||||||
import { Host } from "@clusterio/host";
|
import { Host } from "@clusterio/host";
|
||||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
describe("messages/host", function() {
|
describe("messages/host", function() {
|
||||||
/** @type {Host} */
|
/** @type {Host} */
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
|||||||
|
|
||||||
import { Controller, ControlConnection } from "@clusterio/controller";
|
import { Controller, ControlConnection } from "@clusterio/controller";
|
||||||
import { externalTest } from "../integration/index.js";
|
import { externalTest } from "../integration/index.js";
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
describe("messages/mod", function() {
|
describe("messages/mod", function() {
|
||||||
/** @type {Controller} */
|
/** @type {Controller} */
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import * as lib from "@clusterio/lib";
|
|||||||
import { Controller, ControlConnection } from "@clusterio/controller";
|
import { Controller, ControlConnection } from "@clusterio/controller";
|
||||||
import { Host } from "@clusterio/host";
|
import { Host } from "@clusterio/host";
|
||||||
|
|
||||||
|
import "../setup_logging.js";
|
||||||
|
|
||||||
describe("messages/plugin", function() {
|
describe("messages/plugin", function() {
|
||||||
/** @type {Host} */
|
/** @type {Host} */
|
||||||
let 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