1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { spawn } = require('child_process'); 5 6// Regression test for https://github.com/nodejs/node/issues/27097. 7// Check that (cat [p1] ; cat [p2]) | cat [p3] works. 8 9const p3 = spawn('cat', { stdio: ['pipe', 'pipe', 'inherit'] }); 10const p1 = spawn('cat', { stdio: ['pipe', p3.stdin, 'inherit'] }); 11const p2 = spawn('cat', { stdio: ['pipe', p3.stdin, 'inherit'] }); 12p3.stdout.setEncoding('utf8'); 13 14// Write three different chunks: 15// - 'hello' from this process to p1 to p3 back to us 16// - 'world' from this process to p2 to p3 back to us 17// - 'foobar' from this process to p3 back to us 18// Do so sequentially in order to avoid race conditions. 19p1.stdin.end('hello\n'); 20p3.stdout.once('data', common.mustCall((chunk) => { 21 assert.strictEqual(chunk, 'hello\n'); 22 p2.stdin.end('world\n'); 23 p3.stdout.once('data', common.mustCall((chunk) => { 24 assert.strictEqual(chunk, 'world\n'); 25 p3.stdin.end('foobar\n'); 26 p3.stdout.once('data', common.mustCall((chunk) => { 27 assert.strictEqual(chunk, 'foobar\n'); 28 })); 29 })); 30})); 31