Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBryan English <bryan@bryanenglish.com>2017-09-23 11:40:35 +0300
committerMyles Borins <mylesborins@google.com>2017-10-24 00:35:51 +0300
commite1cff102f454b9474586d3f77fee38389b78d005 (patch)
tree8ab1b8fb2103c343e8ed1073e56982f12a49e5e3 /test
parent7e1a187df17b7ebad6ac977a374f0b138f98f43e (diff)
tty,doc: add type-check to isatty
Previously, various inputs other than non-negative integers would produce incorrect results. Added type-checking on input, returning false for anything other than non-negative integers. Also clarified in docs. PR-URL: https://github.com/nodejs/node/pull/15567 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/pseudo-tty/test-tty-isatty.js17
-rw-r--r--test/pseudo-tty/test-tty-isatty.out0
2 files changed, 17 insertions, 0 deletions
diff --git a/test/pseudo-tty/test-tty-isatty.js b/test/pseudo-tty/test-tty-isatty.js
new file mode 100644
index 00000000000..3a7b2940311
--- /dev/null
+++ b/test/pseudo-tty/test-tty-isatty.js
@@ -0,0 +1,17 @@
+'use strict';
+
+require('../common');
+const { strictEqual } = require('assert');
+const { isatty } = require('tty');
+
+strictEqual(isatty(0), true, 'stdin reported to not be a tty, but it is');
+strictEqual(isatty(1), true, 'stdout reported to not be a tty, but it is');
+strictEqual(isatty(2), true, 'stderr reported to not be a tty, but it is');
+
+strictEqual(isatty(-1), false, '-1 reported to be a tty, but it is not');
+strictEqual(isatty(55555), false, '55555 reported to be a tty, but it is not');
+strictEqual(isatty(1.1), false, '1.1 reported to be a tty, but it is not');
+strictEqual(isatty('1'), false, '\'1\' reported to be a tty, but it is not');
+strictEqual(isatty({}), false, '{} reported to be a tty, but it is not');
+strictEqual(isatty(() => {}), false,
+ '() => {} reported to be a tty, but it is not');
diff --git a/test/pseudo-tty/test-tty-isatty.out b/test/pseudo-tty/test-tty-isatty.out
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/test/pseudo-tty/test-tty-isatty.out