repl: add welcome message
PR-URL: https://github.com/nodejs/node/pull/25947 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
parent
f3b5cc0807
commit
fe963149f6
@ -11,17 +11,21 @@ const {
|
||||
evalScript
|
||||
} = require('internal/process/execution');
|
||||
|
||||
const console = require('internal/console/global');
|
||||
|
||||
prepareMainThreadExecution();
|
||||
|
||||
// --entry-type flag not supported in REPL
|
||||
if (require('internal/options').getOptionValue('--entry-type')) {
|
||||
// If we can't write to stderr, we'd like to make this a noop,
|
||||
// so use console.error.
|
||||
const { error } = require('internal/console/global');
|
||||
error('Cannot specify --entry-type for REPL');
|
||||
console.error('Cannot specify --entry-type for REPL');
|
||||
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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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('');
|
||||
|
@ -86,7 +86,7 @@ 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) {
|
||||
@ -94,8 +94,9 @@ replProc.on('close', function(code) {
|
||||
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
|
||||
@ -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> "));
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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,
|
||||
[
|
||||
|
@ -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);
|
||||
|
@ -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', '']);
|
||||
}));
|
||||
|
||||
|
@ -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');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user