Skip to content

Commit 8e69026

Browse files
Trotttargos
authored andcommitted
test: remove getTTYfd() from common module
common.getTTYfd() is used in one test only. Move it's definition to that test and out of the common module. PR-URL: #17781 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent a8d9ccf commit 8e69026

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

test/common/index.js

-17
Original file line numberDiff line numberDiff line change
@@ -770,23 +770,6 @@ exports.crashOnUnhandledRejection = function() {
770770
(err) => process.nextTick(() => { throw err; }));
771771
};
772772

773-
exports.getTTYfd = function getTTYfd() {
774-
const tty = require('tty');
775-
let tty_fd = 0;
776-
if (!tty.isatty(tty_fd)) tty_fd++;
777-
else if (!tty.isatty(tty_fd)) tty_fd++;
778-
else if (!tty.isatty(tty_fd)) tty_fd++;
779-
else {
780-
try {
781-
tty_fd = fs.openSync('/dev/tty');
782-
} catch (e) {
783-
// There aren't any tty fd's available to use.
784-
return -1;
785-
}
786-
}
787-
return tty_fd;
788-
};
789-
790773
// Hijack stdout and stderr
791774
const stdWrite = {};
792775
function hijackStdWritable(name, listener) {

test/sequential/test-async-wrap-getasyncid.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,24 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check
256256

257257
{
258258
// Do our best to grab a tty fd.
259-
const tty_fd = common.getTTYfd();
259+
function getTTYfd() {
260+
const tty = require('tty');
261+
let tty_fd = 0;
262+
if (!tty.isatty(tty_fd)) tty_fd++;
263+
else if (!tty.isatty(tty_fd)) tty_fd++;
264+
else if (!tty.isatty(tty_fd)) tty_fd++;
265+
else {
266+
try {
267+
tty_fd = fs.openSync('/dev/tty');
268+
} catch (e) {
269+
// There aren't any tty fd's available to use.
270+
return -1;
271+
}
272+
}
273+
return tty_fd;
274+
}
275+
276+
const tty_fd = getTTYfd();
260277
if (tty_fd >= 0) {
261278
const tty_wrap = process.binding('tty_wrap');
262279
// fd may still be invalid, so guard against it.

0 commit comments

Comments
 (0)