mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
A spec reporter subclass buffers console output, including winston's ConsoleTransport and the integration child process lines, and prints it above the failure line when a test or hook fails. VERBOSE_TEST streams everything as before, and CI sets it on debug re-runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
// Spec reporter that holds back console output and prints it only for
|
|
// failing tests and hooks. Set VERBOSE_TEST to print everything as it happens.
|
|
"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"];
|
|
|
|
class CaptureReporter extends Spec {
|
|
constructor(runner, options) {
|
|
super(runner, options);
|
|
if (process.env.VERBOSE_TEST) {
|
|
return;
|
|
}
|
|
|
|
const original = {};
|
|
const captured = [];
|
|
for (const method of methods) {
|
|
original[method] = console[method];
|
|
console[method] = (...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;
|