-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadline.js
39 lines (34 loc) · 849 Bytes
/
readline.js
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
const {EventEmitter} = require('events');
const util = require('util');
const sinon = require('sinon');
const _ = require('lodash');
const stub = {};
_.assign(stub, {
write: sinon.stub().returns(stub),
moveCursor: sinon.stub().returns(stub),
setPrompt: sinon.stub().returns(stub),
close: sinon.stub().returns(stub),
pause: sinon.stub().returns(stub),
resume: sinon.stub().returns(stub),
_getCursorPos: sinon.stub().returns({
cols: 0,
rows: 0
}),
output: {
end: sinon.stub(),
mute: sinon.stub(),
unmute: sinon.stub(),
__raw__: '',
write(str) {
this.__raw__ += str;
}
}
});
const ReadlineStub = function (...args) {
this.line = '';
this.input = new EventEmitter();
EventEmitter.apply(this, args);
};
util.inherits(ReadlineStub, EventEmitter);
_.assign(ReadlineStub.prototype, stub);
module.exports = ReadlineStub;