summaryrefslogtreecommitdiff
path: root/test/pseudo-tty/test-stderr-stdout-handle-sigwinch.js
blob: d5f187d1c3948d28d7f7b44f4d483ebf5eef99a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const common = require('../common');

const originalRefreshSizeStderr = process.stderr._refreshSize;
const originalRefreshSizeStdout = process.stdout._refreshSize;

const wrap = (fn, ioStream, string) => {
  const wrapped = common.mustCall(() => {
    // The console.log() call prints a string that is in the .out file. In other
    // words, the console.log() is part of the test, not extraneous debugging.
    console.log(string);
    try {
      fn.call(ioStream);
    } catch (e) {
      // EINVAL happens on SmartOS if emulation is incomplete
      if (!common.isSunOS || e.code !== 'EINVAL')
        throw e;
    }
  });
  return wrapped;
};

process.stderr._refreshSize = wrap(originalRefreshSizeStderr,
                                   process.stderr,
                                   'calling stderr._refreshSize');
process.stdout._refreshSize = wrap(originalRefreshSizeStdout,
                                   process.stdout,
                                   'calling stdout._refreshSize');

// In AIX, the child exits even before the python parent
// can setup the readloop. Provide a reasonable delay.
setTimeout(function() {
  process.emit('SIGWINCH');
}, common.isAIX ? 200 : 0);