nodejs/test/parallel/test-repl-function-definition-edge-case.js
Dario Piotrowicz 53abd1a7e2
test: add missing newlines to repl .exit writes
some tests write `.exit` into a repl server without
including a newline character (`\n`), such commands
are therefore simply not executed at all, the changes
here add the missing newlines and as a side effect
remove no longer necessary `end` calls

PR-URL: https://github.com/nodejs/node/pull/58041
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
2025-04-28 20:19:07 +00:00

38 lines
891 B
JavaScript

// Reference: https://github.com/nodejs/node/pull/7624
'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
const stream = require('stream');
const r = initRepl();
r.input.emit('data', 'function a() { return 42; } (1)\n');
r.input.emit('data', 'a\n');
r.input.emit('data', '.exit\n');
r.once('exit', common.mustCall());
const expected = '1\n[Function: a]\n';
const got = r.output.accumulator.join('');
assert.strictEqual(got, expected);
function initRepl() {
const input = new stream();
input.write = input.pause = input.resume = () => {};
input.readable = true;
const output = new stream();
output.writable = true;
output.accumulator = [];
output.write = (data) => output.accumulator.push(data);
return repl.start({
input,
output,
useColors: false,
terminal: false,
prompt: ''
});
}