Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4302648

Browse filesBrowse 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
Copy full SHA for 4302648

File tree

Expand file treeCollapse file tree

1 file changed

+43
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+43
-0
lines changed
Open diff view settings
Collapse file
+43Lines 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+
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(/\nsay1\thelp for say1\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(/> hello node developer/.test(output), 'say1 outputted incorrectly');
42+
inputStream.write('.say2 node developer\n');
43+
assert(/> hello from say2/.test(output), 'say2 outputted incorrectly');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.