include stdout into the detail-float
All checks were successful
tests / test (push) Successful in 7s
All checks were successful
tests / test (push) Successful in 7s
This commit is contained in:
36
reporter/test_samurai_jest_stdout.js
Normal file
36
reporter/test_samurai_jest_stdout.js
Normal file
@@ -0,0 +1,36 @@
|
||||
'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);
|
||||
Reference in New Issue
Block a user