mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
The reporter now handles all three modes: verbose prints everything, normal prints output from failing tests and hooks, silent prints only the results. The integration spawn helper and setup_logging no longer filter output themselves. npm install output in plugin install now goes through the logger instead of inherited stdio, so it follows the log level and is captured in tests like the rest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
// Spec reporter controlling console output with TEST_OUTPUT:
|
|
// verbose prints everything, normal (default) prints only output from failing
|
|
// tests and hooks, silent prints only the results.
|
|
"use strict";
|
|
const util = require("node:util");
|
|
const Mocha = require("mocha");
|
|
|
|
const { Spec } = Mocha.reporters;
|
|
const { EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING } = Mocha.Runner.constants;
|
|
const methods = ["log", "info", "debug", "warn", "error"];
|
|
const modes = ["verbose", "normal", "silent"];
|
|
|
|
class CaptureReporter extends Spec {
|
|
constructor(runner, options) {
|
|
super(runner, options);
|
|
const mode = process.env.TEST_OUTPUT || "normal";
|
|
if (!modes.includes(mode)) {
|
|
throw new Error(`Invalid TEST_OUTPUT "${mode}", expected one of ${modes.join(", ")}`);
|
|
}
|
|
if (mode === "verbose") {
|
|
return;
|
|
}
|
|
|
|
const original = {};
|
|
const captured = [];
|
|
for (const method of methods) {
|
|
original[method] = console[method];
|
|
console[method] = mode === "silent"
|
|
? () => {}
|
|
: (...args) => { captured.push([method, util.format(...args)]); };
|
|
}
|
|
|
|
const discard = () => { captured.length = 0; };
|
|
runner.on(EVENT_TEST_PASS, discard);
|
|
runner.on(EVENT_TEST_PENDING, discard);
|
|
// Prepend so the output lands above the failure line.
|
|
runner.prependListener(EVENT_TEST_FAIL, () => {
|
|
for (const [method, text] of captured) {
|
|
original[method](text);
|
|
}
|
|
discard();
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = CaptureReporter;
|