streaming.js
1.57 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
createStream
} from './../../../src';
import expectTable from './expectTable';
describe('README.md usage/', () => {
describe('process.stdout.write', () => {
let processStdoutWriteBuffer;
/**
* @var {Function} Reference to the original process.stdout.write function.
*/
const processStdoutWrite = process.stdout.write;
/**
* @returns {undefined}
*/
const overwriteProcessStdoutWrite = () => {
processStdoutWriteBuffer = '';
process.stdout.write = (text) => {
processStdoutWriteBuffer += text;
};
};
/**
* @returns {string}
*/
const resetProcessStdoudWrite = () => {
process.stdout.write = processStdoutWrite;
return processStdoutWriteBuffer;
};
it('streaming', () => {
const config = {
columnCount: 3,
columnDefault: {
width: 2
}
};
const stream = createStream(config);
overwriteProcessStdoutWrite();
stream.write(['0A', '0B', '0C']);
stream.write(['1A', '1B', '1C']);
stream.write(['2A', '2B', '2C']);
const output = resetProcessStdoudWrite();
expectTable(output + '\n', '╔════╤════╤════╗\n║ 0A │ 0B │ 0C ║\n╚════╧════╧════╝\r\u001b[K╟────┼────┼────╢\n║ 1A │ 1B │ 1C ║\n╚════╧════╧════╝\r\u001b[K╟────┼────┼────╢\n║ 2A │ 2B │ 2C ║\n╚════╧════╧════╝');
});
});
});