aboutsummaryrefslogtreecommitdiff
path: root/test/pseudo-tty/test-handle-wrap-isrefed-tty.js
blob: 33b59b3f1a335edbcdce0a4e6ebc25a50d114314 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';

// see also test/parallel/test-handle-wrap-isrefed.js

const common = require('../common');
const strictEqual = require('assert').strictEqual;
const ReadStream = require('tty').ReadStream;
const tty = new ReadStream(0);
const isTTY = process.binding('tty_wrap').isTTY;
strictEqual(isTTY(0), true, 'tty_wrap: stdin is not a TTY');
strictEqual(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'),
            true, 'tty_wrap: hasRef() missing');
strictEqual(tty._handle.hasRef(),
            true, 'tty_wrap: not initially refed');
tty.unref();
strictEqual(tty._handle.hasRef(),
            false, 'tty_wrap: unref() ineffective');
tty.ref();
strictEqual(tty._handle.hasRef(),
            true, 'tty_wrap: ref() ineffective');
tty._handle.close(common.mustCall(() =>
  strictEqual(tty._handle.hasRef(),
              false, 'tty_wrap: not unrefed on close')));