mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 11:13:55 +00:00

Export a new common.noop no-operation function for general use. Allow using common.mustCall() without a fn argument to simplify test cases. Replace various non-op functions throughout tests with common.noop PR-URL: https://github.com/nodejs/node/pull/12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
39 lines
886 B
JavaScript
39 lines
886 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');
|
|
|
|
common.globalCheck = false;
|
|
|
|
const r = initRepl();
|
|
|
|
r.input.emit('data', 'function a() { return 42; } (1)\n');
|
|
r.input.emit('data', 'a\n');
|
|
r.input.emit('data', '.exit');
|
|
|
|
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 = common.noop;
|
|
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: ''
|
|
});
|
|
}
|