diff --git a/bin/tessel-2.js b/bin/tessel-2.js index 15479a68..79b8312f 100755 --- a/bin/tessel-2.js +++ b/bin/tessel-2.js @@ -41,10 +41,10 @@ function makeCommand(commandName) { flag: true, help: 'Use only a USB connection' }) - .option('lan_prefer', { + .option('lanPrefer', { flag: true, default: false, - help: 'Prefer a LAN connection if it\'s available, otherwise use USB' + help: 'Prefer a LAN connection when available, otherwise use USB.' }); } @@ -109,13 +109,16 @@ makeCommand('restart') makeCommand('run') .callback(function(opts) { + opts.lanPrefer = true; opts.push = false; + // Overridden in tarBundle if opts.full is `true` + opts.slim = true; callControllerWith('deployScript', opts); }) .option('entryPoint', { position: 1, required: true, - help: 'The entry point file to deploy to Tessel' + help: 'The program entry point file to deploy to Tessel' }) .option('single', { flag: true, @@ -129,28 +132,32 @@ makeCommand('run') }) .option('slim', { flag: true, - help: 'Bundle only the required modules' + default: true, + help: 'Deploy a single "bundle" file that contains that contains only the required files, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is run from "slimPath" file (if not provided, a default name is given).', }) .option('slimPath', { - default: 'build.js' + default: '__tessel_program__.js', + help: 'Specify the name of the --slim bundle file.', }) - // Overrides default lan_prefer because deploys require high bandwidth - .option('lan_prefer', { + .option('full', { flag: true, - default: true, - help: 'Prefer a LAN connection if it\'s available, otherwise use USB' + default: false, + help: 'Deploy all files in project including those not used by the program, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is run from specified "entryPoint" file.' }) .help('Deploy a script to Tessel and run it with Node'); makeCommand('push') .callback(function(opts) { + opts.lanPrefer = true; opts.push = true; + // Overridden in tarBundle if opts.full is `true` + opts.slim = true; callControllerWith('deployScript', opts); }) .option('entryPoint', { position: 1, required: true, - help: 'The entry point file to deploy to Tessel' + help: 'The program entry point file to deploy to Tessel' }) .option('single', { flag: true, @@ -164,10 +171,17 @@ makeCommand('push') }) .option('slim', { flag: true, - help: 'Bundle only the required modules' + default: true, + help: 'Push a single "bundle" file that contains that contains only the required files, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is run from "slimPath" file (if not provided, a default name is given).' }) .option('slimPath', { - default: 'index.js' + default: '__tessel_program__.js', + help: 'Specify the name of the --slim bundle file.' + }) + .option('full', { + flag: true, + default: false, + help: 'Push all files in project including those not used by the program, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is run from specified "entryPoint" file.' }) .help('Pushes the file/dir to Flash memory to be run anytime the Tessel is powered, runs the file immediately once the file is copied over'); diff --git a/test/unit/bin-tessel-2.js b/test/unit/bin-tessel-2.js index f1bc2053..53c3b39c 100644 --- a/test/unit/bin-tessel-2.js +++ b/test/unit/bin-tessel-2.js @@ -31,7 +31,7 @@ var defaults = { string: '--usb', }, key: Tessel.LOCAL_AUTH_KEY, - lan_prefer: { + lanPrefer: { flag: true, default: false, help: 'Prefer a LAN connection if it\'s available, otherwise use USB' @@ -97,9 +97,7 @@ exports['Tessel (cli: restart)'] = { test.equal(this.restartScript.callCount, 1); // We must wait for the command to complete // or else the sandbox will be cleared too early - setImmediate(function() { - test.done(); - }); + setImmediate(test.done); }, exitCodeOne: function(test) { @@ -152,7 +150,7 @@ exports['Tessel (cli: update)'] = { _: ['update'], timeout: 5, key: Tessel.LOCAL_AUTH_KEY, - lan_prefer: false + lanPrefer: false }); cli(['update', '--list', ' ']); @@ -175,9 +173,7 @@ exports['Tessel (cli: update)'] = { // We must wait for the command to complete // or else the sandbox will be cleared to early - setImmediate(function() { - test.done(); - }); + setImmediate(test.done); }, exitCodeOne: function(test) { @@ -227,9 +223,7 @@ exports['Tessel (cli: provision)'] = { // We must wait for the command to complete // or else the sandbox will be cleared to early - setImmediate(function() { - test.done(); - }); + setImmediate(test.done); }, exitCodeOne: function(test) { @@ -376,6 +370,117 @@ exports['Tessel (cli: root)'] = { }; +exports['Tessel (cli: run)'] = { + setUp: function(done) { + this.sandbox = sinon.sandbox.create(); + this.warn = this.sandbox.stub(logs, 'warn'); + this.info = this.sandbox.stub(logs, 'info'); + this.deployScript = this.sandbox.stub(controller, 'deployScript').returns(Promise.resolve()); + this.successfulCommand = this.sandbox.stub(cli, 'closeSuccessfulCommand'); + done(); + }, + + tearDown: function(done) { + this.sandbox.restore(); + done(); + }, + + defaultOptions: function(test) { + test.expect(5); + + cli(['run', 'index.js']); + + test.equal(this.deployScript.callCount, 1); + + var args = this.deployScript.lastCall.args[0]; + + // These represent the minimum required properties + // and default values for `t2 run index.js` + test.ok(args.lanPrefer); + test.ok(args.slim); + + test.ok(!args.full); + test.ok(!args.push); + + setImmediate(test.done); + }, + + fullSetTrue_slimOverriddenLater: function(test) { + test.expect(5); + + cli(['run', 'index.js', '--full=true']); + + test.equal(this.deployScript.callCount, 1); + + var args = this.deployScript.lastCall.args[0]; + + // opts.full will override opts.slim in `tarBundle` + // (See test/unit/deploy.js) + test.ok(args.full); + test.ok(args.lanPrefer); + test.ok(args.slim); + + test.ok(!args.push); + + setImmediate(test.done); + }, +}; + +exports['Tessel (cli: push)'] = { + setUp: function(done) { + this.sandbox = sinon.sandbox.create(); + this.warn = this.sandbox.stub(logs, 'warn'); + this.info = this.sandbox.stub(logs, 'info'); + this.deployScript = this.sandbox.stub(controller, 'deployScript').returns(Promise.resolve()); + this.successfulCommand = this.sandbox.stub(cli, 'closeSuccessfulCommand'); + done(); + }, + + tearDown: function(done) { + this.sandbox.restore(); + done(); + }, + + defaultOptions: function(test) { + test.expect(5); + + cli(['push', 'index.js']); + + test.equal(this.deployScript.callCount, 1); + + var args = this.deployScript.lastCall.args[0]; + + // These represent the minimum required properties + // and default values for `t2 push index.js` + test.ok(args.lanPrefer); + test.ok(args.slim); + test.ok(args.push); + + test.ok(!args.full); + + setImmediate(test.done); + }, + + fullSetTrue_slimOverriddenLater: function(test) { + test.expect(5); + + cli(['push', 'index.js', '--full=true']); + + test.equal(this.deployScript.callCount, 1); + + var args = this.deployScript.lastCall.args[0]; + + // opts.full will override opts.slim in `tarBundle` + // (See test/unit/deploy.js) + test.ok(args.full); + test.ok(args.lanPrefer); + test.ok(args.push); + test.ok(args.slim); + + setImmediate(test.done); + }, +}; + exports['closeFailedCommand'] = { setUp: function(done) { this.sandbox = sinon.sandbox.create(); diff --git a/test/unit/update.js b/test/unit/update.js index de642436..34c11f77 100644 --- a/test/unit/update.js +++ b/test/unit/update.js @@ -19,7 +19,7 @@ exports['controller.update'] = { this.tessel = TesselSimulator(); this.getTessel = this.sandbox.stub(Tessel, 'get', function(opts) { - this.tessel.setLANConnectionPreference(opts.lan_prefer); + this.tessel.setLANConnectionPreference(opts.lanPrefer); return Promise.resolve(this.tessel); }.bind(this)); @@ -124,7 +124,7 @@ exports['controller.update'] = { var opts = { version: '0.0.1', - lan_prefer: true + lanPrefer: true }; controller.update(opts) .then(function() { @@ -158,7 +158,7 @@ exports['controller.update'] = { var opts = { version: '0.0.1', - lan_prefer: true + lanPrefer: true }; controller.update(opts) @@ -242,7 +242,7 @@ exports['controller.update'] = { }); var opts = { - lan_prefer: true + lanPrefer: true }; controller.update(opts) .then(function() { @@ -300,7 +300,7 @@ exports['controller.update'] = { }); var opts = { - lan_prefer: true + lanPrefer: true }; controller.update(opts) .then(function() { @@ -363,7 +363,7 @@ exports['controller.update'] = { }.bind(this)); var opts = { - lan_prefer: true + lanPrefer: true }; controller.update(opts) .catch(function(err) { @@ -416,7 +416,7 @@ exports['controller.update'] = { var opts = { force: true, - lan_prefer: true + lanPrefer: true }; controller.update(opts) @@ -473,7 +473,7 @@ exports['controller.update'] = { var opts = { version: 'latest', - lan_prefer: true + lanPrefer: true }; controller.update(opts) @@ -512,7 +512,7 @@ exports['controller.update'] = { var opts = { version: 'x.x.x', - lan_prefer: true + lanPrefer: true }; controller.update(opts) .catch(function(message) { @@ -558,7 +558,7 @@ exports['controller.update'] = { }); var opts = { - lan_prefer: true + lanPrefer: true }; controller.update(opts) .then(function() { @@ -614,7 +614,7 @@ exports['controller.update'] = { }); var opts = { - lan_prefer: true + lanPrefer: true }; controller.update(opts) .then(function() {