File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ require ( '../common' ) ;
4
+
5
+ const stream = require ( 'stream' ) ,
6
+ assert = require ( 'assert' ) ,
7
+ repl = require ( 'repl' ) ;
8
+
9
+ var output = '' ;
10
+ const inputStream = new stream . PassThrough ( ) ;
11
+ const outputStream = new stream . PassThrough ( ) ;
12
+ outputStream . on ( 'data' , function ( d ) {
13
+ output += d ;
14
+ } ) ;
15
+
16
+ const r = 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 ( / \n s a y 1 \t h e l p f o r s a y 1 \n / . test ( output ) , 'help for say1 not present' ) ;
39
+ assert ( / \n s a y 2 \t \n / . test ( output ) , 'help for say2 not present' ) ;
40
+ inputStream . write ( '.say1 node developer\n' ) ;
41
+ assert ( / > h e l l o n o d e d e v e l o p e r / . test ( output ) , 'say1 outputted incorrectly' ) ;
42
+ inputStream . write ( '.say2 node developer\n' ) ;
43
+ assert ( / > h e l l o f r o m s a y 2 / . test ( output ) , 'say2 outputted incorrectly' ) ;
You can’t perform that action at this time.
0 commit comments