node/test/pseudo-tty/ref_keeps_node_running.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

31 lines
720 B
JavaScript

// Flags: --expose-internals --no-warnings
'use strict';
require('../common');
const { internalBinding } = require('internal/test/binding');
const { TTY, isTTY } = internalBinding('tty_wrap');
const assert = require('assert');
assert.ok(isTTY(0), 'fd 0 is not a TTY');
const handle = new TTY(0);
handle.readStart();
handle.onread = () => {};
function isHandleActive(handle) {
return process._getActiveHandles().some((active) => active === handle);
}
assert.ok(isHandleActive(handle), 'TTY handle not initially active');
handle.unref();
assert.ok(!isHandleActive(handle), 'TTY handle active after unref()');
handle.ref();
assert.ok(isHandleActive(handle), 'TTY handle inactive after ref()');
handle.unref();