Skip to content
Permalink
Browse files

Fix subsequent calls to setRawMode

  • Loading branch information...
vadimdemedes committed Mar 5, 2019
1 parent f7386d7 commit 3dba8838932a42f87192ed81183499137bcc2bb0
Showing with 81 additions and 1 deletion.
  1. +1 −0 src/components/App.js
  2. +43 −1 test/exit.js
  3. +37 −0 test/fixtures/exit-double-raw-mode.js
@@ -59,6 +59,7 @@ export default class App extends PureComponent {

if (isEnabled) {
stdin.addListener('data', this.handleInput);
stdin.resume();
} else {
stdin.removeListener('data', this.handleInput);
stdin.pause();
@@ -1,4 +1,4 @@
import test from 'ava';
import {serial as test} from 'ava';
import {spawn} from 'node-pty';

const run = fixture => {
@@ -56,3 +56,45 @@ test('exit on unmount() with raw mode', async t => {
const output = await run('exit-raw-on-unmount');
t.true(output.includes('exited'));
});

test.cb('don\'t exit while raw mode is active', t => {
const term = spawn('node', ['./fixtures/run', './exit-double-raw-mode'], {
name: 'xterm-color',
cols: 100,
cwd: __dirname,
env: process.env
});

let output = '';

term.on('data', data => {
output += data;
});

let isExited = false;

term.on('exit', code => {
isExited = true;

if (code === 0) {
t.true(output.includes('exited'));
t.pass();
t.end();
return;
}

t.fail();
t.end();
});

setTimeout(() => {
t.false(isExited);
term.write('q');
}, 2000);

setTimeout(() => {
term.kill();
t.fail();
t.end();
}, 2500);
});
@@ -0,0 +1,37 @@
/* eslint-disable react/prop-types */
'use strict';
const React = require('react');
const {render, Box, StdinContext} = require('../..');

class ExitDoubleRawMode extends React.Component {
render() {
return <Box>Hello World</Box>;
}

componentDidMount() {
const {setRawMode} = this.props;

setRawMode(true);

setTimeout(() => {
setRawMode(false);
setRawMode(true);
}, 500);
}
}

const {unmount, waitUntilExit} = render((
<StdinContext.Consumer>
{({setRawMode}) => (
<ExitDoubleRawMode setRawMode={setRawMode}/>
)}
</StdinContext.Consumer>
));

process.stdin.on('data', data => {
if (String(data) === 'q') {
unmount();
}
});

waitUntilExit().then(() => console.log('exited'));

0 comments on commit 3dba883

Please sign in to comment.
You can’t perform that action at this time.