Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: add welcome message #25947

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference for keeping the welcome message at the very top and to include preloaded output afterwards. But I am not sure if that's significantly more work or not. If it is, I am fine to keep it as is. We could still change it at some point.

});

// 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', '']);
gengjiawen marked this conversation as resolved.
Show resolved Hide resolved
}));

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