Skip to content

Instantly share code, notes, and snippets.

@rcmedeiros
rcmedeiros / capture_stream_2.ts
Created March 20, 2020 05:36
Capture stdout with callback
import { WriteStream } from 'tty';
type callback = (error: Error | null | undefined) => void;
export const captureStream = (stream: WriteStream, nextLines: number, ccb: (data: string) => void): void => {
const oldWrite = stream.write;
let output = '';
let lines = 0;
stream.write = (chunk: unknown, encoding: string | callback, cb?: callback): boolean => {
const c = chunk.toString();
@rcmedeiros
rcmedeiros / capture_stream.ts
Last active March 20, 2020 04:29
Mocha capture stdout
import { WriteStream } from 'tty';
type callback = (error: Error | null | undefined) => void;
export interface Capture {
unhook: () => void;
captured: () => string;
}
export const captureStream = (stream: WriteStream): Capture => {
const oldWrite = stream.write;