mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05: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>
42 lines
939 B
JavaScript
42 lines
939 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const spawn = require('child_process').spawn;
|
|
|
|
const cat = spawn(common.isWindows ? 'more' : 'cat');
|
|
cat.stdin.write('hello');
|
|
cat.stdin.write(' ');
|
|
cat.stdin.write('world');
|
|
|
|
assert.strictEqual(true, cat.stdin.writable);
|
|
assert.strictEqual(false, cat.stdin.readable);
|
|
|
|
cat.stdin.end();
|
|
|
|
let response = '';
|
|
|
|
cat.stdout.setEncoding('utf8');
|
|
cat.stdout.on('data', function(chunk) {
|
|
console.log(`stdout: ${chunk}`);
|
|
response += chunk;
|
|
});
|
|
|
|
cat.stdout.on('end', common.mustCall());
|
|
|
|
cat.stderr.on('data', common.mustNotCall());
|
|
|
|
cat.stderr.on('end', common.mustCall());
|
|
|
|
cat.on('exit', common.mustCall(function(status) {
|
|
assert.strictEqual(0, status);
|
|
}));
|
|
|
|
cat.on('close', common.mustCall(function() {
|
|
if (common.isWindows) {
|
|
assert.strictEqual('hello world\r\n', response);
|
|
} else {
|
|
assert.strictEqual('hello world', response);
|
|
}
|
|
}));
|