Skip to content

Commit

Permalink
test: remove getTTYfd() from common module
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
Trott committed Dec 21, 2017
1 parent fc8e821 commit ddf3655
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
17 changes: 0 additions & 17 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,23 +823,6 @@ exports.crashOnUnhandledRejection = function() {
(err) => process.nextTick(() => { throw err; }));
};

exports.getTTYfd = function getTTYfd() {
const tty = require('tty');
let tty_fd = 0;
if (!tty.isatty(tty_fd)) tty_fd++;
else if (!tty.isatty(tty_fd)) tty_fd++;
else if (!tty.isatty(tty_fd)) tty_fd++;
else {
try {
tty_fd = fs.openSync('/dev/tty');
} catch (e) {
// There aren't any tty fd's available to use.
return -1;
}
}
return tty_fd;
};

// Hijack stdout and stderr
const stdWrite = {};
function hijackStdWritable(name, listener) {
Expand Down
19 changes: 18 additions & 1 deletion test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,24 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check

{
// Do our best to grab a tty fd.
const tty_fd = common.getTTYfd();
function getTTYfd() {
const tty = require('tty');
let tty_fd = 0;
if (!tty.isatty(tty_fd)) tty_fd++;
else if (!tty.isatty(tty_fd)) tty_fd++;
else if (!tty.isatty(tty_fd)) tty_fd++;
else {
try {
tty_fd = fs.openSync('/dev/tty');
} catch (e) {
// There aren't any tty fd's available to use.
return -1;
}
}
return tty_fd;
}

const tty_fd = getTTYfd();
if (tty_fd >= 0) {
const tty_wrap = process.binding('tty_wrap');
// fd may still be invalid, so guard against it.
Expand Down

0 comments on commit ddf3655

Please sign in to comment.