xref: /third_party/node/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciif (process.argv[2] === 'child')
61cb0ef41Sopenharmony_ci  process.stdout.end('foo');
71cb0ef41Sopenharmony_cielse
81cb0ef41Sopenharmony_ci  parent();
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cifunction parent() {
111cb0ef41Sopenharmony_ci  const spawn = require('child_process').spawn;
121cb0ef41Sopenharmony_ci  const child = spawn(process.execPath, [__filename, 'child']);
131cb0ef41Sopenharmony_ci  let out = '';
141cb0ef41Sopenharmony_ci  let err = '';
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  child.stdout.setEncoding('utf8');
171cb0ef41Sopenharmony_ci  child.stderr.setEncoding('utf8');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  child.stdout.on('data', function(c) {
201cb0ef41Sopenharmony_ci    out += c;
211cb0ef41Sopenharmony_ci  });
221cb0ef41Sopenharmony_ci  child.stderr.on('data', function(c) {
231cb0ef41Sopenharmony_ci    err += c;
241cb0ef41Sopenharmony_ci  });
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  child.on('close', function(code, signal) {
271cb0ef41Sopenharmony_ci    assert.strictEqual(code, 0);
281cb0ef41Sopenharmony_ci    assert.strictEqual(err, '');
291cb0ef41Sopenharmony_ci    assert.strictEqual(out, 'foo');
301cb0ef41Sopenharmony_ci    console.log('ok');
311cb0ef41Sopenharmony_ci  });
321cb0ef41Sopenharmony_ci}
33

Indexes created Thu Nov 07 10:32:03 CST 2024