xref: /third_party/node/test/parallel/test-stdin-pipe-resume.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci// This tests that piping stdin will cause it to resume() as well.
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') {
71cb0ef41Sopenharmony_ci  process.stdin.pipe(process.stdout);
81cb0ef41Sopenharmony_ci} else {
91cb0ef41Sopenharmony_ci  const spawn = require('child_process').spawn;
101cb0ef41Sopenharmony_ci  const buffers = [];
111cb0ef41Sopenharmony_ci  const child = spawn(process.execPath, [__filename, 'child']);
121cb0ef41Sopenharmony_ci  child.stdout.on('data', function(c) {
131cb0ef41Sopenharmony_ci    buffers.push(c);
141cb0ef41Sopenharmony_ci  });
151cb0ef41Sopenharmony_ci  child.stdout.on('close', function() {
161cb0ef41Sopenharmony_ci    const b = Buffer.concat(buffers).toString();
171cb0ef41Sopenharmony_ci    assert.strictEqual(b, 'Hello, world\n');
181cb0ef41Sopenharmony_ci    console.log('ok');
191cb0ef41Sopenharmony_ci  });
201cb0ef41Sopenharmony_ci  child.stdin.write('Hel');
211cb0ef41Sopenharmony_ci  child.stdin.write('lo,');
221cb0ef41Sopenharmony_ci  child.stdin.write(' wo');
231cb0ef41Sopenharmony_ci  setTimeout(function() {
241cb0ef41Sopenharmony_ci    child.stdin.write('rld\n');
251cb0ef41Sopenharmony_ci    child.stdin.end();
261cb0ef41Sopenharmony_ci  }, 10);
271cb0ef41Sopenharmony_ci}
28

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