title: 'This socket is closed' when stdout is listened in Mocha test
body: <p>This test</p>
  
  <pre><code>it.only('should not throw', () =&gt; {
      var output = '';
  
      function callback(data) {
          output += data.toString();
      }
  
      process.stdout.on('data', callback); // error is thrown at this line
      // ...
      process.stdout.removeListener('data', callback);
  })
  </code></pre>
  
  <p>throws an error:</p>
  
  <pre><code>Error: This socket is closed                                                                           
      at WriteStream.Socket._writeGeneric (net.js:679:19)                                                
      at WriteStream.Socket._write (net.js:730:8)                                                        
      at doWrite (_stream_writable.js:331:12)                                                            
      at writeOrBuffer (_stream_writable.js:317:5)                                                       
      at WriteStream.Writable.write (_stream_writable.js:243:11)                                         
      at WriteStream.Socket.write (net.js:657:40)                                                        
      at Console.log (console.js:43:16)                                                                  
      at Runner.&lt;anonymous&gt; (node_modules\mocha\lib\reporters\spec.js:80:13)
      at emitTwo (events.js:111:20)                                                                      
      at Runner.emit (events.js:191:7)                                                                   
      at Runner.fail (node_modules\mocha\lib\runner.js:251:8)               
      at Runner.uncaught (node_modules\mocha\lib\runner.js:757:8)           
      at process.uncaught (node_modules\mocha\lib\runner.js:839:10)         
      at emitOne (events.js:96:13)                                                                       
      at process.emit (events.js:188:7)                                                                  
      at process._fatalException (bootstrap_node.js:297:26)                                              
  </code></pre>
  
  <p>Where <code>node_modules\mocha\lib\reporters\spec.js:80:13</code> are these Mocha lines:</p>
  
  <pre><code>  runner.on('fail', function(test) {
      console.log(indent() + color('fail', '  %d) %s'), ++n, test.title);
    });
  </code></pre>
  
  <p>It's supposed to test code that outputs to <code>process.stdout</code> with <code>spawn</code>, but I wasn't able to get to this part; the error is thrown instantly on <code>process.stdout.on('data', ...)</code> call.</p>
  
  <p>The problem persists with latest Mocha (5.2.0) and default configuration, a reporter in use doesn't affect the result.</p>
  
  <p>What is going on and how can <code>process.stdout</code> be listened? If this is impossible, how can stdout from spawned process be tested in Mocha otherwise?</p>