3 * Copyright (c) 2017, Daniel Imms (MIT License).
4 * Copyright (c) 2018, Microsoft Corporation (MIT License).
6 Object.defineProperty(exports, "__esModule", { value: true });
7 var unixTerminal_1 = require("./unixTerminal");
8 var assert = require("assert");
9 var path = require("path");
10 var testUtils_test_1 = require("./testUtils.test");
11 var FIXTURES_PATH = path.normalize(path.join(__dirname, '..', 'fixtures', 'utf8-character.txt'));
12 if (process.platform !== 'win32') {
13 describe('UnixTerminal', function () {
14 describe('Constructor', function () {
15 it('should set a valid pts name', function () {
16 var term = new unixTerminal_1.UnixTerminal('/bin/bash', [], {});
18 if (process.platform === 'linux') {
19 // https://linux.die.net/man/4/pts
20 regExp = /^\/dev\/pts\/\d+$/;
22 if (process.platform === 'darwin') {
23 // https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man4/pty.4.html
24 regExp = /^\/dev\/tty[p-sP-S][a-z0-9]+$/;
27 assert.ok(regExp.test(term._pty), '"' + term._pty + '" should match ' + regExp.toString());
31 describe('PtyForkEncodingOption', function () {
32 it('should default to utf8', function (done) {
33 var term = new unixTerminal_1.UnixTerminal('/bin/bash', ['-c', "cat \"" + FIXTURES_PATH + "\""]);
34 term.on('data', function (data) {
35 assert.equal(typeof data, 'string');
36 assert.equal(data, '\u00E6');
40 it('should return a Buffer when encoding is null', function (done) {
41 var term = new unixTerminal_1.UnixTerminal('/bin/bash', ['-c', "cat \"" + FIXTURES_PATH + "\""], {
44 term.on('data', function (data) {
45 assert.equal(typeof data, 'object');
46 assert.ok(data instanceof Buffer);
47 assert.equal(0xC3, data[0]);
48 assert.equal(0xA6, data[1]);
52 it('should support other encodings', function (done) {
54 var term = new unixTerminal_1.UnixTerminal(null, ['-c', 'echo "' + text + '"'], {
58 term.on('data', function (data) {
59 assert.equal(typeof data, 'string');
62 term.on('exit', function () {
63 assert.equal(Buffer.alloc(8, buffer, 'base64').toString().replace('\r', '').replace('\n', ''), text);
68 describe('open', function () {
70 afterEach(function () {
73 term.master.destroy();
76 it('should open a pty with access to a master and slave socket', function (done) {
77 var doneCalled = false;
78 term = unixTerminal_1.UnixTerminal.open({});
80 term.slave.on('data', function (data) {
84 term.master.on('data', function (data) {
87 testUtils_test_1.pollUntil(function () {
88 if (masterbuf === 'slave\r\nmaster\r\n' && slavebuf === 'master\n') {
94 term.slave.write('slave\n');
95 term.master.write('master\n');
100 //# sourceMappingURL=unixTerminal.test.js.map