UNPKG

6.14 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright (c) 2017, Daniel Imms (MIT License).
4 * Copyright (c) 2018, Microsoft Corporation (MIT License).
5 */
6var __extends = (this && this.__extends) || (function () {
7 var extendStatics = function (d, b) {
8 extendStatics = Object.setPrototypeOf ||
9 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
11 return extendStatics(d, b);
12 };
13 return function (d, b) {
14 extendStatics(d, b);
15 function __() { this.constructor = d; }
16 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17 };
18})();
19Object.defineProperty(exports, "__esModule", { value: true });
20var assert = require("assert");
21var windowsTerminal_1 = require("./windowsTerminal");
22var unixTerminal_1 = require("./unixTerminal");
23var terminal_1 = require("./terminal");
24var terminalConstructor = (process.platform === 'win32') ? windowsTerminal_1.WindowsTerminal : unixTerminal_1.UnixTerminal;
25var SHELL = (process.platform === 'win32') ? 'cmd.exe' : '/bin/bash';
26var terminalCtor;
27if (process.platform === 'win32') {
28 terminalCtor = require('./windowsTerminal');
29}
30else {
31 terminalCtor = require('./unixTerminal');
32}
33var TestTerminal = /** @class */ (function (_super) {
34 __extends(TestTerminal, _super);
35 function TestTerminal() {
36 return _super !== null && _super.apply(this, arguments) || this;
37 }
38 TestTerminal.prototype.checkType = function (name, value, type, allowArray) {
39 if (allowArray === void 0) { allowArray = false; }
40 this._checkType(name, value, type, allowArray);
41 };
42 TestTerminal.prototype._write = function (data) {
43 throw new Error('Method not implemented.');
44 };
45 TestTerminal.prototype.resize = function (cols, rows) {
46 throw new Error('Method not implemented.');
47 };
48 TestTerminal.prototype.destroy = function () {
49 throw new Error('Method not implemented.');
50 };
51 TestTerminal.prototype.kill = function (signal) {
52 throw new Error('Method not implemented.');
53 };
54 Object.defineProperty(TestTerminal.prototype, "process", {
55 get: function () {
56 throw new Error('Method not implemented.');
57 },
58 enumerable: true,
59 configurable: true
60 });
61 Object.defineProperty(TestTerminal.prototype, "master", {
62 get: function () {
63 throw new Error('Method not implemented.');
64 },
65 enumerable: true,
66 configurable: true
67 });
68 Object.defineProperty(TestTerminal.prototype, "slave", {
69 get: function () {
70 throw new Error('Method not implemented.');
71 },
72 enumerable: true,
73 configurable: true
74 });
75 return TestTerminal;
76}(terminal_1.Terminal));
77describe('Terminal', function () {
78 describe('constructor', function () {
79 it('should do basic type checks', function () {
80 assert.throws(function () { return new terminalCtor('a', 'b', { 'name': {} }); }, 'name must be a string (not a object)');
81 });
82 });
83 describe('checkType', function () {
84 it('should throw for the wrong type', function () {
85 var t = new TestTerminal();
86 assert.doesNotThrow(function () { return t.checkType('foo', 'test', 'string'); });
87 assert.doesNotThrow(function () { return t.checkType('foo', 1, 'number'); });
88 assert.doesNotThrow(function () { return t.checkType('foo', {}, 'object'); });
89 assert.throws(function () { return t.checkType('foo', 'test', 'number'); });
90 assert.throws(function () { return t.checkType('foo', 1, 'object'); });
91 assert.throws(function () { return t.checkType('foo', {}, 'string'); });
92 });
93 it('should throw for wrong types within arrays', function () {
94 var t = new TestTerminal();
95 assert.doesNotThrow(function () { return t.checkType('foo', ['test'], 'string', true); });
96 assert.doesNotThrow(function () { return t.checkType('foo', [1], 'number', true); });
97 assert.doesNotThrow(function () { return t.checkType('foo', [{}], 'object', true); });
98 assert.throws(function () { return t.checkType('foo', ['test'], 'number', true); });
99 assert.throws(function () { return t.checkType('foo', [1], 'object', true); });
100 assert.throws(function () { return t.checkType('foo', [{}], 'string', true); });
101 });
102 });
103 describe('automatic flow control', function () {
104 it('should respect ctor flow control options', function () {
105 var pty = new terminalConstructor(SHELL, [], { handleFlowControl: true, flowControlPause: 'abc', flowControlResume: '123' });
106 assert.equal(pty.handleFlowControl, true);
107 assert.equal(pty._flowControlPause, 'abc');
108 assert.equal(pty._flowControlResume, '123');
109 });
110 // TODO: I don't think this test ever worked due to pollUntil being used incorrectly
111 // it('should do flow control automatically', async function(): Promise<void> {
112 // // Flow control doesn't work on Windows
113 // if (process.platform === 'win32') {
114 // return;
115 // }
116 // this.timeout(10000);
117 // const pty = new terminalConstructor(SHELL, [], {handleFlowControl: true, flowControlPause: 'PAUSE', flowControlResume: 'RESUME'});
118 // let read: string = '';
119 // pty.on('data', data => read += data);
120 // pty.on('pause', () => read += 'paused');
121 // pty.on('resume', () => read += 'resumed');
122 // pty.write('1');
123 // pty.write('PAUSE');
124 // pty.write('2');
125 // pty.write('RESUME');
126 // pty.write('3');
127 // await pollUntil(() => {
128 // return stripEscapeSequences(read).endsWith('1pausedresumed23');
129 // }, 100, 10);
130 // });
131 });
132});
133function stripEscapeSequences(data) {
134 return data.replace(/\u001b\[0K/, '');
135}
136//# sourceMappingURL=terminal.test.js.map
\No newline at end of file