test: modernize test-child-process-flush-stdio

PR-URL: https://github.com/nodejs/node/pull/23504
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Viacheslav Liakhov 2018-10-12 10:20:32 -07:00 committed by Ruben Bridgewater
parent 50572c0a73
commit 0b1be75f27
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -9,7 +9,7 @@ const opts = { shell: common.isWindows };
const p = cp.spawn('echo', [], opts);
p.on('close', common.mustCall(function(code, signal) {
p.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
spawnWithReadable();
@ -17,17 +17,17 @@ p.on('close', common.mustCall(function(code, signal) {
p.stdout.read();
function spawnWithReadable() {
const spawnWithReadable = () => {
const buffer = [];
const p = cp.spawn('echo', ['123'], opts);
p.on('close', common.mustCall(function(code, signal) {
p.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(Buffer.concat(buffer).toString().trim(), '123');
}));
p.stdout.on('readable', function() {
p.stdout.on('readable', () => {
let buf;
while (buf = this.read())
while (buf = p.stdout.read())
buffer.push(buf);
});
}
};