node/test/parallel/test-force-repl-with-eval.js
gengjiawen fe963149f6
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>
2019-04-16 03:37:03 +02:00

24 lines
524 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
// Spawn a node child process in "interactive" mode (force the repl) and eval
const cp = spawn(process.execPath, ['-i', '-e', 'console.log("42")']);
let gotToEnd = false;
cp.stdout.setEncoding('utf8');
let output = '';
cp.stdout.on('data', function(b) {
output += b;
if (output.endsWith('> 42\n')) {
gotToEnd = true;
cp.kill();
}
});
process.on('exit', function() {
assert(gotToEnd);
});