installed pty
[VSoRC/.git] / node_modules / node-pty / src / terminal.test.ts
1 /**
2  * Copyright (c) 2017, Daniel Imms (MIT License).
3  * Copyright (c) 2018, Microsoft Corporation (MIT License).
4  */
5
6 import * as assert from 'assert';
7 import { WindowsTerminal } from './windowsTerminal';
8 import { UnixTerminal } from './unixTerminal';
9 import { pollUntil } from './testUtils.test';
10
11 const terminalConstructor = (process.platform === 'win32') ? WindowsTerminal : UnixTerminal;
12 const SHELL = (process.platform === 'win32') ? 'cmd.exe' : '/bin/bash';
13
14 let terminalCtor: WindowsTerminal | UnixTerminal;
15 if (process.platform === 'win32') {
16   terminalCtor = require('./windowsTerminal');
17 } else {
18   terminalCtor = require('./unixTerminal');
19 }
20
21
22 describe('Terminal', () => {
23   describe('constructor', () => {
24     it('should do basic type checks', () => {
25       assert.throws(
26         () => new (<any>terminalCtor)('a', 'b', { 'name': {} }),
27         'name must be a string (not a object)'
28       );
29     });
30   });
31
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');
38     });
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') {
43     //     return;
44     //   }
45
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');
52     //   pty.write('1');
53     //   pty.write('PAUSE');
54     //   pty.write('2');
55     //   pty.write('RESUME');
56     //   pty.write('3');
57     //   await pollUntil(() => {
58     //     return stripEscapeSequences(read).endsWith('1pausedresumed23');
59     //   }, 100, 10);
60     // });
61   });
62 });
63
64 function stripEscapeSequences(data: string): string {
65   return data.replace(/\u001b\[0K/, '');
66 }