-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathcreate-stdout.ts
More file actions
28 lines (21 loc) 路 686 Bytes
/
Copy pathcreate-stdout.ts
File metadata and controls
28 lines (21 loc) 路 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import EventEmitter from 'node:events';
import {spy} from 'sinon';
// Fake process.stdout
export type FakeStdout = {
get: () => string;
getWrites: () => string[];
} & NodeJS.WriteStream;
const createStdout = (columns?: number, isTTY?: boolean, rows?: number): FakeStdout => {
const stdout = new EventEmitter() as unknown as FakeStdout;
stdout.columns = columns ?? 100;
stdout.isTTY = isTTY ?? true;
if (rows !== undefined) {
stdout.rows = rows;
}
const write = spy();
stdout.write = write;
stdout.get = () => write.lastCall.args[0] as string;
stdout.getWrites = () => (write.args as string[][]).map(args => args[0]!);
return stdout;
};
export default createStdout;