Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: fix buggy getTTYfd() implementation
  • Loading branch information
Trott committed Dec 20, 2017
commit 8be12593d562535433b31a16a865ed24b07cd335
17 changes: 7 additions & 10 deletions test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,28 +249,25 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check
// Do our best to grab a tty fd.
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 {
let ttyFd = [0, 1, 2].find(tty.isatty);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I read it - I'm surprised isatty is synchronous :D Change LGTM

if (ttyFd === undefined) {
try {
tty_fd = fs.openSync('/dev/tty');
ttyFd = fs.openSync('/dev/tty');
} catch (e) {
// There aren't any tty fd's available to use.
return -1;
}
}
return tty_fd;
return ttyFd;
}

const tty_fd = getTTYfd();
if (tty_fd >= 0) {
const ttyFd = getTTYfd();
if (ttyFd >= 0) {
const tty_wrap = process.binding('tty_wrap');
// fd may still be invalid, so guard against it.
const handle = (() => {
try {
return new tty_wrap.TTY(tty_fd, false);
return new tty_wrap.TTY(ttyFd, false);
} catch (e) {
return null;
}
Expand Down