Only print test output for failing tests

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>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-17 12:27:29 +00:00
1 parent 5cf14eb15b
commit 838a43428b
4 files changed
+47 -1

No files matched your search

+6
View File
@@ -67,9 +67,15 @@ jobs:
run: wget -q -O factorio.tar.gz https://www.factorio.com/get-download/${{ matrix.factorio-version }}/headless/linux64 && tar -xf factorio.tar.gz && rm factorio.tar.gz
- name: Run tests
if: ${{ !matrix.coverage }}
env:
# Re-run with debug logging to see output from passing tests
VERBOSE_TEST: ${{ runner.debug }}
run: pnpm test --grep "^(Integration of Clusterio (clusterioctl|plugin system)|Clusterio Instance) " ${{ matrix.tests == 'other' && '--invert' || '' }}
- name: Run coverage
if: ${{ matrix.coverage }}
env:
# Re-run with debug logging to see output from passing tests
VERBOSE_TEST: ${{ runner.debug }}
run: pnpm run ci-cover --grep "^(Integration of Clusterio (clusterioctl|plugin system)|Clusterio Instance) " ${{ matrix.tests == 'other' && '--invert' || '' }}
- name: Upload coverage to Codecov
if: ${{ matrix.coverage }}
+2
View File
@@ -197,6 +197,8 @@ Use `pnpm run fast-test` to skip tests marked as slow, or `pnpm run no-external-
These correspond to setting the `FAST_TEST` and `NO_EXTERNAL_TEST` environment variables and can be combined.
For example, `FAST_TEST=y NO_EXTERNAL_TEST=y pnpm test` combines both exclusions.
These flags still run the remaining integration setup and tests; neither produces an isolated unit-test run.
Console and log output is only printed for tests and hooks that fail, just above the failure.
Set `VERBOSE_TEST=y` to print all of it as it happens, or re-run a CI job with debug logging enabled.
When writing slow tests call `slowTest(this)`, and for external API tests call `externalTest(this)`; both are exported from `test/common.js`.
For tests that need a Factorio installation, call `requiresFactorio(this)` in the test or pass the suite to `requiresFactorio`, imported from `test/integration/index.js`.
`test/common.js` also provides JSON round-trip/schema helpers, and `test/mock.js` provides shared mocks.
+1 -1
View File
@@ -8,7 +8,7 @@
"build": "tsc --build",
"watch": "tsc --build --watch",
"build-mod": "pnpm run -r build-mod --output-dir ../../dist",
"test": "pnpm run build && NODE_EXTRA_CA_CERTS=$(pwd)/test/file/tls/cert.pem mocha --enable-source-maps --check-leaks -R spec --recursive test \"plugins/*/test/**\" --exclude \"test/manual/**\"",
"test": "pnpm run build && NODE_EXTRA_CA_CERTS=$(pwd)/test/file/tls/cert.pem mocha --enable-source-maps --check-leaks -R ./test/reporter.cjs --recursive test \"plugins/*/test/**\" --exclude \"test/manual/**\"",
"silent-test": "SILENT_TEST=y pnpm test",
"fast-test": "FAST_TEST=y pnpm test",
"no-external-test": "NO_EXTERNAL_TEST=y pnpm test",
+38
View File
@@ -0,0 +1,38 @@
// 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;