0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/pseudo-tty/test-tty-isatty.js
Bryan English 27e12e7524 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>
2017-10-22 16:51:10 -07:00

18 lines
824 B
JavaScript

'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');