2 * Copyright (c) 2017, Daniel Imms (MIT License).
3 * Copyright (c) 2018, Microsoft Corporation (MIT License).
6 import * as assert from 'assert';
7 import { WindowsTerminal } from './windowsTerminal';
8 import { UnixTerminal } from './unixTerminal';
9 import { pollUntil } from './testUtils.test';
11 const terminalConstructor = (process.platform === 'win32') ? WindowsTerminal : UnixTerminal;
12 const SHELL = (process.platform === 'win32') ? 'cmd.exe' : '/bin/bash';
14 let terminalCtor: WindowsTerminal | UnixTerminal;
15 if (process.platform === 'win32') {
16 terminalCtor = require('./windowsTerminal');
18 terminalCtor = require('./unixTerminal');
22 describe('Terminal', () => {
23 describe('constructor', () => {
24 it('should do basic type checks', () => {
26 () => new (<any>terminalCtor)('a', 'b', { 'name': {} }),
27 'name must be a string (not a object)'
32 describe('automatic flow control', () => {
33 it('should respect ctor flow control options', () => {
34 const pty = new terminalConstructor(SHELL, [], {handleFlowControl: true, flowControlPause: 'abc', flowControlResume: '123'});
35 assert.equal(pty.handleFlowControl, true);
36 assert.equal((pty as any)._flowControlPause, 'abc');
37 assert.equal((pty as any)._flowControlResume, '123');
39 // TODO: I don't think this test ever worked due to pollUntil being used incorrectly
40 // it('should do flow control automatically', async function(): Promise<void> {
41 // // Flow control doesn't work on Windows
42 // if (process.platform === 'win32') {
46 // this.timeout(10000);
47 // const pty = new terminalConstructor(SHELL, [], {handleFlowControl: true, flowControlPause: 'PAUSE', flowControlResume: 'RESUME'});
48 // let read: string = '';
49 // pty.on('data', data => read += data);
50 // pty.on('pause', () => read += 'paused');
51 // pty.on('resume', () => read += 'resumed');
53 // pty.write('PAUSE');
55 // pty.write('RESUME');
57 // await pollUntil(() => {
58 // return stripEscapeSequences(read).endsWith('1pausedresumed23');
64 function stripEscapeSequences(data: string): string {
65 return data.replace(/\u001b\[0K/, '');