Skip to content

Commit 4302648

Browse files
benglrvagg
authored andcommitted
test: add test for repl.defineCommand()
It also tests displayPrompt by checking for '> '. PR-URL: #3908 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent c61237d commit 4302648

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
conststream=require('stream'),
6+
assert=require('assert'),
7+
repl=require('repl');
8+
9+
varoutput='';
10+
constinputStream=newstream.PassThrough();
11+
constoutputStream=newstream.PassThrough();
12+
outputStream.on('data',function(d){
13+
output+=d;
14+
});
15+
16+
constr=repl.start({
17+
input: inputStream,
18+
output: outputStream,
19+
terminal: true
20+
});
21+
22+
r.defineCommand('say1',{
23+
help: 'help for say1',
24+
action: function(thing){
25+
output='';
26+
this.write('hello '+thing);
27+
this.displayPrompt();
28+
}
29+
});
30+
31+
r.defineCommand('say2',function(){
32+
output='';
33+
this.write('hello from say2');
34+
this.displayPrompt();
35+
});
36+
37+
inputStream.write('.help\n');
38+
assert(/\nsay1\thelpforsay1\n/.test(output),'help for say1 not present');
39+
assert(/\nsay2\t\n/.test(output),'help for say2 not present');
40+
inputStream.write('.say1 node developer\n');
41+
assert(/>hellonodedeveloper/.test(output),'say1 outputted incorrectly');
42+
inputStream.write('.say2 node developer\n');
43+
assert(/>hellofromsay2/.test(output),'say2 outputted incorrectly');

0 commit comments

Comments
 (0)