Remove dependency on sleep module

This commit is contained in:
Daniel Imms
2017-07-08 17:32:47 -07:00
parent cb53cdd728
commit 740d4a45f9
2 changed files with 33 additions and 31 deletions
-1
View File
@@ -58,7 +58,6 @@
"merge-stream": "^1.0.1",
"node-pty": "^0.4.1",
"nodemon": "1.10.2",
"sleep": "^3.0.1",
"sorcery": "^0.10.0",
"tslint": "^4.0.2",
"typescript": "~2.2.0",
+33 -30
View File
@@ -2,7 +2,6 @@ var glob = require('glob');
var fs = require('fs');
var os = require('os');
var pty = require('node-pty');
var sleep = require('sleep');
var Terminal = require('../xterm');
if (os.platform() === 'win32') {
@@ -25,17 +24,18 @@ var primitive_pty = pty.native.open(COLS, ROWS);
// we just pipe the data from slave to master as a child program would do
// pty.js opens pipe fds with O_NONBLOCK
// just wait 10ms instead of setting fds to blocking mode
function pty_write_read(s) {
function pty_write_read(s, cb) {
fs.writeSync(primitive_pty.slave, s);
sleep.usleep(10000);
var b = Buffer(64000);
var bytes = fs.readSync(primitive_pty.master, b, 0, 64000);
return b.toString('utf8', 0, bytes);
setTimeout(() => {
var b = Buffer(64000);
var bytes = fs.readSync(primitive_pty.master, b, 0, 64000);
cb(b.toString('utf8', 0, bytes));
});
}
// make sure raw pty is at x=0 and has no pending data
function pty_reset() {
pty_write_read('\r\n');
function pty_reset(cb) {
pty_write_read('\r\n', cb);
}
/* debug helpers */
@@ -106,30 +106,33 @@ describe('xterm output comparison', function() {
continue;
}
(function(filename) {
it(filename.split('/').slice(-1)[0], function () {
pty_reset();
var in_file = fs.readFileSync(filename, 'utf8');
var from_pty = pty_write_read(in_file);
// uncomment this to get log from terminal
//console.log = function(){};
it(filename.split('/').slice(-1)[0], done => {
pty_reset(() => {
var in_file = fs.readFileSync(filename, 'utf8');
pty_write_read(in_file, from_pty => {
// uncomment this to get log from terminal
//console.log = function(){};
// Perform a synchronous .write(data)
xterm.writeBuffer.push(from_pty);
xterm.innerWrite();
// Perform a synchronous .write(data)
xterm.writeBuffer.push(from_pty);
xterm.innerWrite();
var from_emulator = terminalToString(xterm);
console.log = CONSOLE_LOG;
var expected = fs.readFileSync(filename.split('.')[0] + '.text', 'utf8');
// Some of the tests have whitespace on the right of lines, we trim all the linex
// from xterm.js so ignore this for now at least.
var expectedRightTrimmed = expected.split('\n').map(function (l) {
return l.replace(/\s+$/, '');
}).join('\n');
if (from_emulator != expectedRightTrimmed) {
// uncomment to get noisy output
throw new Error(formatError(in_file, from_emulator, expected));
// throw new Error('mismatch');
}
var from_emulator = terminalToString(xterm);
console.log = CONSOLE_LOG;
var expected = fs.readFileSync(filename.split('.')[0] + '.text', 'utf8');
// Some of the tests have whitespace on the right of lines, we trim all the linex
// from xterm.js so ignore this for now at least.
var expectedRightTrimmed = expected.split('\n').map(function (l) {
return l.replace(/\s+$/, '');
}).join('\n');
if (from_emulator != expectedRightTrimmed) {
// uncomment to get noisy output
throw new Error(formatError(in_file, from_emulator, expected));
// throw new Error('mismatch');
}
done();
});
});
});
})(files[i]);
}