Skip to content

Commit

Permalink
t2 run: move JS-specific "post run" operation to a language specific …
Browse files Browse the repository at this point in the history
…definition.

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jul 2, 2016
1 parent 34a16f5 commit fd85356
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 25 deletions.
10 changes: 4 additions & 6 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,13 @@ exportables.run = function(tessel, opts) {

log.spinner.stop();

if (opts.lang.postRun) {
prom = opts.lang.postRun(tessel, remoteProcess);
}

// When the stream closes, return from the function
remoteProcess.once('close', resolve);

if (tessel.connection.connectionType === 'LAN') {
// Pipe input TO the remote process.
process.stdin.pipe(remoteProcess.stdin);
process.stdin.setRawMode(true);
}

// Pipe output FROM the remote process.
remoteProcess.stdout.pipe(process.stdout);
remoteProcess.stderr.pipe(process.stderr);
Expand Down
11 changes: 11 additions & 0 deletions lib/tessel/deployment/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ exportables.preBundle = function(opts) {
return exportables.resolveBinaryModules(opts);
};

// exportables.preRun = function(tessel) {};

exportables.postRun = function(tessel, remote) {
if (tessel.connection.connectionType === 'LAN') {
// Pipe input TO the remote process.
process.stdin.pipe(remote.stdin);
process.stdin.setRawMode(true);
}

return Promise.resolve();
};

function logMissingBinaryModuleWarning(name) {
var warning = tags.stripIndent `
Expand Down
1 change: 1 addition & 0 deletions lib/tessel/deployment/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ exportables.preRun = function(tessel) {
});
};

// exportables.postRun = function(tessel, opts) {};

module.exports = exportables;
29 changes: 10 additions & 19 deletions test/unit/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@ exports['Tessel.prototype.restart'] = {

tearDown: function(done) {
this.tessel.mockClose();

sandbox.restore();

done();
},

Expand Down Expand Up @@ -479,6 +477,7 @@ exports['deploy.run'] = {
done();
},
tearDown: function(done) {
this.tessel.mockClose();
sandbox.restore();
done();
},
Expand Down Expand Up @@ -523,54 +522,45 @@ exports['deploy.run'] = {
});
},

runStdInOutLan: function(test) {
test.expect(4);
runPostRunExistsLAN: function(test) {
test.expect(1);

this.tessel.connection.connectionType = 'LAN';

this.postRun = sandbox.stub(deployment.js, 'postRun', () => Promise.resolve());
this.exec = sandbox.stub(this.tessel.connection, 'exec', (command, options, callback) => {
callback(null, this.tessel._rps);
this.tessel._rps.emit('close');
});

this.stdinPipe = sandbox.stub(process.stdin, 'pipe');
this.stdinSetRawMode = sandbox.stub(process.stdin, 'setRawMode');

deploy.run(this.tessel, {
resolvedEntryPoint: 'foo',
lang: deployment.js,
}).then(() => {
test.equal(this.stdinPipe.callCount, 1);
test.equal(this.stdinPipe.lastCall.args[0], this.tessel._rps.stdin);
test.equal(this.stdinSetRawMode.callCount, 1);
test.equal(this.stdinSetRawMode.lastCall.args[0], true);
test.equal(this.postRun.callCount, 1);
test.done();
});
},

runStdInOutUsb: function(test) {
test.expect(2);
runPostRunExistsUSB: function(test) {
test.expect(1);

this.tessel.connection.connectionType = 'USB';

this.exec = sandbox.stub(this.tessel.connection, 'exec', (command, options, callback) => {
callback(null, this.tessel._rps);
this.tessel._rps.emit('close');
});

this.stdinPipe = sandbox.stub(process.stdin, 'pipe');
this.stdinSetRawMode = sandbox.stub(process.stdin, 'setRawMode');
this.postRun = sandbox.stub(deployment.js, 'postRun', () => Promise.resolve());

deploy.run(this.tessel, {
resolvedEntryPoint: 'foo',
lang: deployment.js,
}).then(() => {
test.equal(this.stdinPipe.callCount, 0);
test.equal(this.stdinSetRawMode.callCount, 0);
test.equal(this.postRun.callCount, 1);
test.done();
});
},

};

exports['deploy.createShellScript'] = {
Expand All @@ -580,6 +570,7 @@ exports['deploy.createShellScript'] = {
done();
},
tearDown: function(done) {
this.tessel.mockClose();
sandbox.restore();
done();
},
Expand Down
44 changes: 44 additions & 0 deletions test/unit/deployment/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ exports['deploy.sendBundle, error handling'] = {
},

tearDown: function(done) {
this.tessel.mockClose();
sandbox.restore();
done();
},
Expand Down Expand Up @@ -2478,6 +2479,7 @@ exports['deploy.createShellScript'] = {
done();
},
tearDown: function(done) {
this.tessel.mockClose();
sandbox.restore();
done();
},
Expand Down Expand Up @@ -2565,3 +2567,45 @@ exports['deployment.js.lists'] = {
}

};


exports['deployment.js.postRun'] = {
setUp: function(done) {
this.info = sandbox.stub(log, 'info');
this.stdinPipe = sandbox.stub(process.stdin, 'pipe');
this.stdinSetRawMode = sandbox.stub(process.stdin, 'setRawMode');
this.tessel = TesselSimulator();
done();
},
tearDown: function(done) {
this.tessel.mockClose();
sandbox.restore();
done();
},

postRunLAN: function(test) {
test.expect(2);

this.tessel.connection.connectionType = 'LAN';
deployment.js.postRun(this.tessel, {
stdin: null
}).then(() => {
test.equal(this.stdinPipe.callCount, 1);
test.equal(this.stdinSetRawMode.callCount, 1);
test.done();
});
},

postRunUSB: function(test) {
test.expect(2);

this.tessel.connection.connectionType = 'USB';
deployment.js.postRun(this.tessel, {
stdin: null
}).then(() => {
test.equal(this.stdinPipe.callCount, 0);
test.equal(this.stdinSetRawMode.callCount, 0);
test.done();
});
},
};

0 comments on commit fd85356

Please sign in to comment.