Files
test-samurai-jest-runner/reporter/test_samurai_jest_stdout.js
M.Schirmer e4b4097999
All checks were successful
tests / test (push) Successful in 7s
include stdout into the detail-float
2026-01-06 12:27:19 +01:00

37 lines
920 B
JavaScript

'use strict';
const util = require('util');
const STDOUT_PREFIX = 'TSAMURAI_STDOUT ';
function getCurrentTestName() {
if (typeof expect !== 'function') return null;
try {
const state = expect.getState();
if (state && state.currentTestName) {
return String(state.currentTestName);
}
} catch (_err) {
return null;
}
return null;
}
function emitStdout(name, args) {
if (!name) return;
const message = util.format(...args);
if (message === '') return;
process.stdout.write(`${STDOUT_PREFIX}${JSON.stringify({ jestName: name, output: message })}\n`);
}
function wrapConsoleMethod(method) {
if (typeof console[method] !== 'function') return;
const original = console[method].bind(console);
console[method] = (...args) => {
emitStdout(getCurrentTestName(), args);
return original(...args);
};
}
['log', 'info', 'warn', 'error', 'debug'].forEach(wrapConsoleMethod);