Skip to content

Commit

Permalink
repl: add welcome message
Browse files Browse the repository at this point in the history
  • Loading branch information
gengjiawen committed Apr 10, 2019
1 parent bd9109c commit c59e4c9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 22 deletions.
3 changes: 3 additions & 0 deletions lib/internal/main/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ if (require('internal/options').getOptionValue('--entry-type')) {
process.exit(1);
}

console.log(`Welcome to Node.js ${process.version}.\n` +
'Type ".help" for more information.');

const cliRepl = require('internal/repl');
cliRepl.createInternalRepl(process.env, (err, repl) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-force-repl-with-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cp.stdout.setEncoding('utf8');
let output = '';
cp.stdout.on('data', function(b) {
output += b;
if (output === '> 42\n') {
if (output.endsWith('> 42\n')) {
gotToEnd = true;
cp.kill();
}
Expand Down
15 changes: 11 additions & 4 deletions test/parallel/test-force-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ const assert = require('assert');
const spawn = require('child_process').spawn;

// Spawn a node child process in interactive mode (enabling the REPL) and
// confirm the '> ' prompt is included in the output.
// confirm the '> ' prompt and welcome message is included in the output.
const cp = spawn(process.execPath, ['-i']);

cp.stdout.setEncoding('utf8');

cp.stdout.once('data', common.mustCall(function(b) {
assert.strictEqual(b, '> ');
cp.kill();
let out = '';
cp.stdout.on('data', (d) => {
out += d;
});

cp.stdout.on('end', common.mustCall(() => {
assert.strictEqual(out, `Welcome to Node.js ${process.version}.\n` +
'Type ".help" for more information.\n> ');
}));

cp.stdin.end('');
9 changes: 5 additions & 4 deletions test/parallel/test-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,17 @@ const replProc = childProcess.spawn(
);
replProc.stdin.end('.exit\n');
let replStdout = '';
replProc.stdout.on('data', function(d) {
replProc.stdout.on('data', (d) => {
replStdout += d;
});
replProc.on('close', function(code) {
assert.strictEqual(code, 0);
const output = [
'A',
'> '
].join('\n');
assert.strictEqual(replStdout, output);
];
assert.ok(replStdout.startsWith(output[0]));
assert.ok(replStdout.endsWith(output[1]));
});

// Test that preload placement at other points in the cmdline
Expand All @@ -114,7 +115,7 @@ const interactive = childProcess.exec(
`"${nodeBinary}" ${preloadOption([fixtureD])}-i`,
common.mustCall(function(err, stdout, stderr) {
assert.ifError(err);
assert.strictEqual(stdout, "> 'test'\n> ");
assert.ok(stdout.endsWith("> 'test'\n> "));
})
);

Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-repl-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ const child = spawn(process.execPath, args);
const input = '(function(){"use strict"; const y=1;y=2})()\n';
// This message will vary based on JavaScript engine, so don't check the message
// contents beyond confirming that the `Error` is a `TypeError`.
const expectOut = /^> Thrown:\nTypeError: /;
const expectOut = /> Thrown:\nTypeError: /;

child.stderr.setEncoding('utf8');
child.stderr.on('data', function(c) {
child.stderr.on('data', (d) => {
throw new Error('child.stderr be silent');
});

child.stdout.setEncoding('utf8');
let out = '';
child.stdout.on('data', function(c) {
out += c;
child.stdout.on('data', (d) => {
out += d;
});
child.stdout.on('end', function() {
child.stdout.on('end', () => {
assert(expectOut.test(out));
console.log('ok');
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-inspect-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ child.stdout.on('data', (data) => {
});

child.on('exit', common.mustCall(() => {
const results = output.replace(/^> /mg, '').split('\n');
const results = output.replace(/^> /mg, '').split('\n').slice(2);
assert.deepStrictEqual(
results,
[
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-require-after-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ child.stdout.on('data', (c) => {
out += c;
});
child.stdout.on('end', common.mustCall(() => {
assert.strictEqual(out, '> 1\n> ');
assert.ok(out.endsWith('> 1\n> '));
}));

child.stdin.end(input);
2 changes: 1 addition & 1 deletion test/parallel/test-repl-require-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ child.stdout.on('data', (data) => {
});

child.on('exit', common.mustCall(() => {
const results = output.replace(/^> /mg, '').split('\n');
const results = output.replace(/^> /mg, '').split('\n').slice(2);
assert.deepStrictEqual(results, ['undefined', 'true', 'true', '']);
}));

Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-repl-unexpected-token-recoverable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ const child = spawn(process.execPath, args);

const input = 'var foo = "bar\\\nbaz"';
// Match '...' as well since it marks a multi-line statement
const expectOut = /^> \.\.\. undefined\n/;
const expectOut = /> \.\.\. undefined\n/;

child.stderr.setEncoding('utf8');
child.stderr.on('data', function(c) {
child.stderr.on('data', (d) => {
throw new Error('child.stderr be silent');
});

child.stdout.setEncoding('utf8');
let out = '';
child.stdout.on('data', function(c) {
out += c;
child.stdout.on('data', (d) => {
out += d;
});

child.stdout.on('end', function() {
child.stdout.on('end', () => {
assert(expectOut.test(out));
console.log('ok');
});
Expand Down

0 comments on commit c59e4c9

Please sign in to comment.