node/test/pseudo-tty/test-handle-wrap-hasref-tty.js
Antoine du Hamel ec26b1c01a
tools: add lint rule to ensure assertions are reached
PR-URL: https://github.com/nodejs/node/pull/60125
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2025-10-07 12:40:05 +00:00

20 lines
757 B
JavaScript

// Flags: --expose-internals --no-warnings
'use strict';
// See also test/parallel/test-handle-wrap-hasref.js
const common = require('../common');
const assert = require('assert');
const ReadStream = require('tty').ReadStream;
const tty = new ReadStream(0);
const { internalBinding } = require('internal/test/binding');
const isTTY = internalBinding('tty_wrap').isTTY;
assert.ok(isTTY(0), 'tty_wrap: stdin is not a TTY');
assert.ok(tty._handle.hasRef(), 'tty_wrap: not initially refed');
tty.unref();
assert.ok(!tty._handle.hasRef(), 'tty_wrap: unref() ineffective');
tty.ref();
assert.ok(tty._handle.hasRef(), 'tty_wrap: ref() ineffective');
tty._handle.close(common.mustCall(() =>
assert.ok(!tty._handle.hasRef(), 'tty_wrap: not unrefed on close')));