Skip to content

Commit

Permalink
t2 run/push: provide node process.versions, passed to pre-compiled mo…
Browse files Browse the repository at this point in the history
…dule resolution. Fixes gh-843

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Sep 13, 2016
1 parent 945eebb commit 4baf27b
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ controller.tesselEnvVersions = opts => {
// Figure out what commit SHA is running on it
var firmwareVersion = updates.findBuild(builds, 'sha', versionSha).version;

return tessel.fetchCurrentNodeVersion()
return tessel.fetchNodeProcessVersion()
.then(nodeVersion => {
log.info(output('CLI', cliVersion));
log.info(output('Firmware', firmwareVersion));
Expand Down
12 changes: 11 additions & 1 deletion lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ Tessel.prototype.memoryInfo = function() {
* @return {Promise}
*/
Tessel.prototype.deploy = function(opts) {

if (typeof opts.tessel === 'undefined') {
opts.tessel = this;
}

// Only an _explicit_ `true` will set push mode
var isPush = opts.push === true;
var entryPoint = opts.entryPoint;
Expand All @@ -129,7 +134,7 @@ Tessel.prototype.deploy = function(opts) {
return new Promise((resolve, reject) => {
// Stop running an existing applications
return this.simpleExec(commands.app.stop())
.catch((error) => {
.catch(error => {
// This _must_ be inline
if (error.length > 0) {
throw new Error(`Remote command: ${commands.app.stop().join(' ')} failed.`);
Expand Down Expand Up @@ -316,6 +321,11 @@ exportables.endOfLookup = function(pushdir) {
};

exportables.sendBundle = function(tessel, opts) {

if (typeof opts.tessel === 'undefined') {
opts.tessel = tessel;
}

return new Promise((resolve, reject) => {
// Execute the remote untar process command
tessel.connection.exec(commands.untarStdin(Tessel.REMOTE_RUN_PATH), (err, remoteProcess) => {
Expand Down
6 changes: 5 additions & 1 deletion lib/tessel/deployment/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ exportables.injectBinaryModules = function(globRoot, tempBundlePath, options) {
};

exportables.preBundle = function(options) {
return exportables.resolveBinaryModules(options);
return options.tessel.fetchNodeProcessVersions()
.then(versions => {
options.tessel.versions = versions;
return exportables.resolveBinaryModules(options);
});
};

exportables.tarBundle = function(options) {
Expand Down
7 changes: 6 additions & 1 deletion lib/tessel/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ var Tessel = require('./tessel');
/*
Gathers node version.
*/
Tessel.prototype.fetchCurrentNodeVersion = function() {
Tessel.prototype.fetchNodeProcessVersion = function() {
return this.simpleExec(['node', '--version'])
.then(version => {
// strip the `v` preceding the version
return version.trim().substring(1);
});
};

Tessel.prototype.fetchNodeProcessVersions = function() {
return this.simpleExec(['node', '-p', 'JSON.stringify(process.versions)'])
.then(versions => JSON.parse(versions.trim()));
};
1 change: 1 addition & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"Project": true,
"Progress": true,
"Promise": true,
"processVersions": true,
"provision": true,
"restore": true,
"reference": true,
Expand Down
11 changes: 11 additions & 0 deletions test/common/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,14 @@ global.extract = function(bundle, callback) {

parser.end(bundle);
};

global.processVersions = {
http_parser: '2.5.2',
node: '4.4.3',
v8: '4.5.103.35',
uv: '1.8.0',
zlib: '1.2.8',
ares: '1.10.1-DEV',
modules: '46',
openssl: '1.0.2d',
};
16 changes: 8 additions & 8 deletions test/unit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ exports['controller.tesselEnvVersions'] = {
return Promise.resolve('9a85c84f5a03c715908921baaaa9e7397985bc7f');
});

this.fetchCurrentNodeVersion = this.sandbox.stub(Tessel.prototype, 'fetchCurrentNodeVersion', () => {
this.fetchNodeProcessVersion = this.sandbox.stub(Tessel.prototype, 'fetchNodeProcessVersion', () => {
return Promise.resolve('4.2.1');
});

Expand Down Expand Up @@ -420,7 +420,7 @@ exports['controller.tesselEnvVersions'] = {
// Get the firmware version
test.equal(this.fetchCurrentBuildInfo.callCount, 1);
// Execute `node --version` command on tessel
test.equal(this.fetchCurrentNodeVersion.callCount, 1);
test.equal(this.fetchNodeProcessVersion.callCount, 1);
// Make sure we have some output
test.equal(this.info.callCount, 3);

Expand Down Expand Up @@ -450,8 +450,8 @@ exports['controller.tesselEnvVersions'] = {
return Promise.resolve('9a85c84f5a03c715908921baaaa9e7397985bc7f');
});

this.fetchCurrentNodeVersion.restore();
this.fetchCurrentNodeVersion = this.sandbox.stub(Tessel.prototype, 'fetchCurrentNodeVersion', () => {
this.fetchNodeProcessVersion.restore();
this.fetchNodeProcessVersion = this.sandbox.stub(Tessel.prototype, 'fetchNodeProcessVersion', () => {
return Promise.reject();
});

Expand All @@ -464,7 +464,7 @@ exports['controller.tesselEnvVersions'] = {
// Get the firmware version
test.equal(this.fetchCurrentBuildInfo.callCount, 1);
// Execute `node --version` command on tessel
test.equal(this.fetchCurrentNodeVersion.callCount, 1);
test.equal(this.fetchNodeProcessVersion.callCount, 1);
// Make sure we have some output
test.equal(this.info.callCount, 3);

Expand Down Expand Up @@ -494,8 +494,8 @@ exports['controller.tesselEnvVersions'] = {
return Promise.reject();
});

this.fetchCurrentNodeVersion.restore();
this.fetchCurrentNodeVersion = this.sandbox.stub(Tessel.prototype, 'fetchCurrentNodeVersion', () => {
this.fetchNodeProcessVersion.restore();
this.fetchNodeProcessVersion = this.sandbox.stub(Tessel.prototype, 'fetchNodeProcessVersion', () => {
return Promise.resolve('4.2.1');
});

Expand All @@ -508,7 +508,7 @@ exports['controller.tesselEnvVersions'] = {
// Get the firmware version
test.equal(this.fetchCurrentBuildInfo.callCount, 1);
// Execute `node --version` command on tessel
test.equal(this.fetchCurrentNodeVersion.callCount, 0);
test.equal(this.fetchNodeProcessVersion.callCount, 0);
// Make sure we have some output
test.equal(this.info.callCount, 3);

Expand Down
8 changes: 5 additions & 3 deletions test/unit/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ exports['Tessel.prototype.deploy'] = {
this.push = sandbox.spy(deploy, 'push');
this.createShellScript = sandbox.spy(deploy, 'createShellScript');

this.injectBinaryModules = sandbox.stub(deployment.js, 'injectBinaryModules', () => Promise.resolve());
this.resolveBinaryModules = sandbox.stub(deployment.js, 'resolveBinaryModules', () => Promise.resolve());
this.injectBinaryModules = sandbox.stub(deployment.js, 'injectBinaryModules').returns(Promise.resolve());
this.resolveBinaryModules = sandbox.stub(deployment.js, 'resolveBinaryModules').returns(Promise.resolve());
this.tarBundle = sandbox.stub(deployment.js, 'tarBundle', function() {
return new Promise(function(resolve) {
resolve(jsCodeReference);
Expand All @@ -133,6 +133,8 @@ exports['Tessel.prototype.deploy'] = {
this.tessel = TesselSimulator();
this.end = sandbox.spy(this.tessel._rps.stdin, 'end');

this.fetchNodeProcessVersions = sandbox.stub(this.tessel, 'fetchNodeProcessVersions').returns(Promise.resolve(processVersions));

this.pWrite = sandbox.stub(Preferences, 'write').returns(Promise.resolve());


Expand Down Expand Up @@ -382,7 +384,7 @@ exports['Tessel.prototype.deploy'] = {
test.equal(err, undefined, 'We hit a catch statement that we should not have.');
});
});
}
},
};

exports['Tessel.prototype.restart'] = {
Expand Down
73 changes: 73 additions & 0 deletions test/unit/deployment/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ exports['Deployment: JavaScript'] = {
this.tessel = TesselSimulator();
this.end = sandbox.spy(this.tessel._rps.stdin, 'end');

this.fetchNodeProcessVersions = sandbox.stub(this.tessel, 'fetchNodeProcessVersions').returns(Promise.resolve(processVersions));

this.pWrite = sandbox.stub(Preferences, 'write').returns(Promise.resolve());

this.spinnerStart = sandbox.stub(log.spinner, 'start');
Expand Down Expand Up @@ -1800,6 +1802,8 @@ exports['deploy.findProject'] = {
exports['deploy.sendBundle, error handling'] = {
setUp: function(done) {
this.tessel = TesselSimulator();
this.fetchNodeProcessVersions = sandbox.stub(this.tessel, 'fetchNodeProcessVersions').returns(Promise.resolve(processVersions));

this.pathResolve = sandbox.stub(path, 'resolve');
this.failure = 'FAIL';
done();
Expand Down Expand Up @@ -1863,6 +1867,75 @@ exports['deploy.sendBundle, error handling'] = {
},
};


exports['deployment.js.preBundle'] = {
setUp: function(done) {
this.tessel = TesselSimulator();

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

this.receive = sandbox.stub(this.tessel, 'receive', (rps, callback) => {
rps.emit('close');
callback();
});

this.fetchNodeProcessVersions = sandbox.stub(this.tessel, 'fetchNodeProcessVersions').returns(Promise.resolve(processVersions));

this.findProject = sandbox.stub(deploy, 'findProject').returns(Promise.resolve({
pushdir: '',
entryPoint: ''
}));
this.resolveBinaryModules = sandbox.stub(deployment.js, 'resolveBinaryModules').returns(Promise.resolve());
this.tarBundle = sandbox.stub(deployment.js, 'tarBundle').returns(Promise.resolve(new Buffer([0x00])));
this.pathResolve = sandbox.stub(path, 'resolve');


this.preBundle = sandbox.spy(deployment.js, 'preBundle');
done();
},

tearDown: function(done) {
this.tessel.mockClose();
sandbox.restore();
done();
},

preBundleReceivesTessel(test) {
test.expect(1);

deploy.sendBundle(this.tessel, {
target: '/',
entryPoint: 'foo.js',
lang: deployment.js
}).then(() => {
test.equal(this.preBundle.lastCall.args[0].tessel, this.tessel);
test.done();
});
},

preBundleCallsfetchNodeProcessVersionsAndForwardsResult(test) {
test.expect(4);

deploy.sendBundle(this.tessel, {
target: '/',
entryPoint: 'foo.js',
lang: deployment.js
}).then(() => {
test.equal(this.fetchNodeProcessVersions.callCount, 1);
test.equal(this.resolveBinaryModules.callCount, 1);

var args = this.resolveBinaryModules.lastCall.args[0];

test.equal(args.tessel, this.tessel);
test.equal(args.tessel.versions, processVersions);
test.done();
});
},
};

exports['deployment.js.resolveBinaryModules'] = {
setUp: function(done) {

Expand Down
29 changes: 22 additions & 7 deletions test/unit/version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test dependencies are required and exposed in common/bootstrap.js
require('../common/bootstrap');

exports['Tessel.prototype.fetchCurrentNodeVersion'] = {
exports['version *'] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
this.warn = this.sandbox.stub(log, 'warn', function() {});
Expand All @@ -12,10 +12,6 @@ exports['Tessel.prototype.fetchCurrentNodeVersion'] = {

this.tessel = TesselSimulator();

this.simpleExec = this.sandbox.stub(Tessel.prototype, 'simpleExec', () => {
return Promise.resolve('v4.2.1');
});

done();
},

Expand All @@ -26,10 +22,12 @@ exports['Tessel.prototype.fetchCurrentNodeVersion'] = {
done();
},

properVersionReturned: function(test) {
'Tessel.prototype.fetchNodeProcessVersion': function(test) {
test.expect(3);

this.tessel.fetchCurrentNodeVersion()
this.simpleExec = this.sandbox.stub(this.tessel, 'simpleExec').returns(Promise.resolve('v4.2.1'));

this.tessel.fetchNodeProcessVersion()
.then(version => {
test.equal(this.simpleExec.callCount, 1);
test.equal(this.simpleExec.calledWith(['node', '--version']), true);
Expand All @@ -40,5 +38,22 @@ exports['Tessel.prototype.fetchCurrentNodeVersion'] = {
test.ok(false, `properVersionReturned failed: ${error.toString()}`);
test.done();
});
},

'Tessel.prototype.fetchNodeProcessVersions': function(test) {
test.expect(3);
this.simpleExec = this.sandbox.stub(this.tessel, 'simpleExec').returns(Promise.resolve(JSON.stringify(processVersions)));

this.tessel.fetchNodeProcessVersions()
.then(version => {
test.equal(this.simpleExec.callCount, 1);
test.equal(this.simpleExec.calledWith(['node', '-p', 'JSON.stringify(process.versions)']), true);
test.deepEqual(version, processVersions);
test.done();
})
.catch(error => {
test.ok(false, `properVersionReturned failed: ${error.toString()}`);
test.done();
});
}
};

0 comments on commit 4baf27b

Please sign in to comment.