2015-11-18 17:42:05 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('../common');
|
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const stream = require('stream');
|
|
|
|
const assert = require('assert');
|
|
|
|
const repl = require('repl');
|
2015-11-18 17:42:05 -08:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let output = '';
|
2015-11-18 17:42:05 -08:00
|
|
|
const inputStream = new stream.PassThrough();
|
|
|
|
const outputStream = new stream.PassThrough();
|
|
|
|
outputStream.on('data', function(d) {
|
|
|
|
output += d;
|
|
|
|
});
|
|
|
|
|
|
|
|
const r = repl.start({
|
|
|
|
input: inputStream,
|
|
|
|
output: outputStream,
|
|
|
|
terminal: true
|
|
|
|
});
|
|
|
|
|
|
|
|
r.defineCommand('say1', {
|
|
|
|
help: 'help for say1',
|
|
|
|
action: function(thing) {
|
|
|
|
output = '';
|
2017-04-28 04:06:42 +03:00
|
|
|
this.write(`hello ${thing}`);
|
2015-11-18 17:42:05 -08:00
|
|
|
this.displayPrompt();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
r.defineCommand('say2', function() {
|
|
|
|
output = '';
|
|
|
|
this.write('hello from say2');
|
|
|
|
this.displayPrompt();
|
|
|
|
});
|
|
|
|
|
2016-08-17 09:47:13 -05:00
|
|
|
inputStream.write('.help\n');
|
2017-03-13 14:50:57 -04:00
|
|
|
assert(/\n\.say1 help for say1\n/.test(output),
|
|
|
|
'help for say1 not present');
|
|
|
|
assert(/\n\.say2\n/.test(output), 'help for say2 not present');
|
2016-08-17 09:47:13 -05:00
|
|
|
inputStream.write('.say1 node developer\n');
|
2015-11-18 17:42:05 -08:00
|
|
|
assert(/> hello node developer/.test(output), 'say1 outputted incorrectly');
|
2016-08-17 09:47:13 -05:00
|
|
|
inputStream.write('.say2 node developer\n');
|
2015-11-18 17:42:05 -08:00
|
|
|
assert(/> hello from say2/.test(output), 'say2 outputted incorrectly');
|