diff --git a/test/pseudo-tty/test-set-raw-mode-reset-process-exit.js b/test/pseudo-tty/test-set-raw-mode-reset-process-exit.js new file mode 100644 index 00000000000000..b6857eaebbdf60 --- /dev/null +++ b/test/pseudo-tty/test-set-raw-mode-reset-process-exit.js @@ -0,0 +1,18 @@ +'use strict'; +require('../common'); +const child_process = require('child_process'); + +// Tests that exiting through process.exit() resets the TTY mode. + +child_process.spawnSync(process.execPath, [ + '-e', 'process.stdin.setRawMode(true); process.exit(0)' +], { stdio: 'inherit' }); + +const { stdout } = child_process.spawnSync('stty', { + stdio: ['inherit', 'pipe', 'inherit'], + encoding: 'utf8' +}); + +if (stdout.match(/-echo\b/)) { + console.log(stdout); +} diff --git a/test/pseudo-tty/test-set-raw-mode-reset-process-exit.out b/test/pseudo-tty/test-set-raw-mode-reset-process-exit.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/pseudo-tty/test-set-raw-mode-reset-signal.js b/test/pseudo-tty/test-set-raw-mode-reset-signal.js new file mode 100644 index 00000000000000..f953a01331c050 --- /dev/null +++ b/test/pseudo-tty/test-set-raw-mode-reset-signal.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); +const child_process = require('child_process'); + +// Tests that exiting through a catchable signal resets the TTY mode. + +const proc = child_process.spawn(process.execPath, [ + '-e', 'process.stdin.setRawMode(true); console.log("Y"); while(true) {}' +], { stdio: ['inherit', 'pipe', 'inherit'] }); + +proc.stdout.on('data', common.mustCall(() => { + proc.kill('SIGINT'); +})); + +proc.on('exit', common.mustCall(() => { + const { stdout } = child_process.spawnSync('stty', { + stdio: ['inherit', 'pipe', 'inherit'], + encoding: 'utf8' + }); + + if (stdout.match(/-echo\b/)) { + console.log(stdout); + } +})); diff --git a/test/pseudo-tty/test-set-raw-mode-reset-signal.out b/test/pseudo-tty/test-set-raw-mode-reset-signal.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/pseudo-tty/test-set-raw-mode-reset.js b/test/pseudo-tty/test-set-raw-mode-reset.js new file mode 100644 index 00000000000000..ab8f1125bfc602 --- /dev/null +++ b/test/pseudo-tty/test-set-raw-mode-reset.js @@ -0,0 +1,19 @@ +'use strict'; +require('../common'); +const child_process = require('child_process'); + +// Tests that exiting through normal means resets the TTY mode. +// Refs: https://github.com/nodejs/node/issues/21020 + +child_process.spawnSync(process.execPath, [ + '-e', 'process.stdin.setRawMode(true)' +], { stdio: 'inherit' }); + +const { stdout } = child_process.spawnSync('stty', { + stdio: ['inherit', 'pipe', 'inherit'], + encoding: 'utf8' +}); + +if (stdout.match(/-echo\b/)) { + console.log(stdout); +} diff --git a/test/pseudo-tty/test-set-raw-mode-reset.out b/test/pseudo-tty/test-set-raw-mode-reset.out new file mode 100644 index 00000000000000..e69de29bb2d1d6