output-interceptor

Intercepts stdout/ stderr.
Implementation
This module uses domain to capture asynchronous function output.
Read Capturing stdout/ stderr in Node.js using Domain module.
Usage
import {
createOutputInterceptor
} from 'output-interceptor';
const interceptOutput = createOutputInterceptor();
const main = async () => {
const result = await interceptOutput(() => {
console.log('foo');
console.error('bar');
return Promise.resolve('baz');
});
result === 'baz';
interceptOutput.output === 'foo\nbar\n';
};
main();
API
export type OutputInterceptorUserConfigurationType = {|
+interceptStderr?: boolean,
+interceptStdout?: boolean,
+stripAnsi?: boolean
|};
type FlushType = () => string;
export type OutputInterceptorType = {|
<T>(routine: () => Promise<T> | T): Promise<T>,
output: ''
|};
createOutputInterceptor(userConfiguration?: OutputInterceptorUserConfigurationType): OutputInterceptorType;