• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5
6// This test ensures that Node.js will not ignore tty 'readable' subscribers
7// when it's the only tty subscriber and the only thing keeping event loop alive
8// https://github.com/nodejs/node/issues/20503
9
10process.stdin.setEncoding('utf8');
11
12const expectedInput = ['foo', 'bar', null];
13
14process.stdin.on('readable', common.mustCall(function() {
15  const data = process.stdin.read();
16  assert.strictEqual(data, expectedInput.shift());
17}, 3)); // first 2 data, then end
18
19process.stdin.on('end', common.mustCall());
20
21setTimeout(() => {
22  process.stdin.push('foo');
23  process.nextTick(() => {
24    process.stdin.push('bar');
25    process.nextTick(() => {
26      process.stdin.push(null);
27    });
28  });
29}, 1);
30