From a6bfe29301ec5c7d22c01fe00c7f60ed440110de Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 18 Jul 2016 16:03:58 -0400 Subject: [PATCH] =?UTF-8?q?Make=20code=20compression=20optional,=20default?= =?UTF-8?q?=20to=20=E2=80=94compress=3Dtrue.=20Fixes=20gh-776?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `t2 run --compress=false` will skip the code compression step Signed-off-by: Rick Waldron --- bin/tessel-2.js | 5 +++ lib/tessel/deployment/javascript.js | 2 +- test/unit/deployment/javascript.js | 54 +++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/bin/tessel-2.js b/bin/tessel-2.js index 40a66d3e..28fb5b21 100755 --- a/bin/tessel-2.js +++ b/bin/tessel-2.js @@ -203,6 +203,11 @@ makeCommand('run') default: false, help: 'Deploy a project containing all files within, 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 started from specified file.' }) + .option('compress', { + flag: true, + default: true, + help: 'Compression steps during deployment. To skip compression, use --compress=false.' + }) .option('rustcc', { default: 'http://192.241.138.79:49160', help: 'Specify the location and port of the Rust cross-compilation server.' diff --git a/lib/tessel/deployment/javascript.js b/lib/tessel/deployment/javascript.js index c067e114..b4c9abb9 100644 --- a/lib/tessel/deployment/javascript.js +++ b/lib/tessel/deployment/javascript.js @@ -503,7 +503,7 @@ exportables.tarBundle = function(options) { return; } - if (isJS) { + if (options.compress && isJS) { try { source = exportables.compress(source, compressionOptions); } catch (error) { diff --git a/test/unit/deployment/javascript.js b/test/unit/deployment/javascript.js index 2a09e915..f57f4317 100644 --- a/test/unit/deployment/javascript.js +++ b/test/unit/deployment/javascript.js @@ -172,6 +172,7 @@ exports['Deployment: JavaScript'] = { // Actually deploy the script this.tessel.deploy({ entryPoint: path.relative(process.cwd(), DEPLOY_FILE_JS), + compress: true, push: false, single: false }) @@ -542,6 +543,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), + compress: true, full: true, }).then(bundle => { @@ -612,6 +614,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(bundle => { // These things happen in the --slim path @@ -670,6 +673,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(bundle => { extract(bundle, (error, entries) => { @@ -690,6 +694,34 @@ exports['deployment.js.tarBundle'] = { }); }, + compressionIsSkipped: function(test) { + test.expect(1); + + var entryPoint = 'index.js'; + var target = 'test/unit/fixtures/syntax-error'; + + deployment.js.tarBundle({ + target: path.normalize(target), + resolvedEntryPoint: entryPoint, + compress: false, + slim: true, + }).then(bundle => { + extract(bundle, (error, entries) => { + if (error) { + test.ok(false, error.toString()); + test.done(); + } + + // compression mechanism is never called when --compress=false + test.equal(this.compress.callCount, 0); + test.done(); + }); + }).catch(() => { + test.ok(false, 'Compression should not produce errors'); + test.done(); + }); + }, + slimTesselInit: function(test) { test.expect(5); @@ -707,6 +739,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(bundle => { test.equal(this.project.callCount, 1); @@ -739,6 +772,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), entryPoint: entryPoint, + compress: true, resolvedEntryPoint: entryPoint, single: true, slim: true, @@ -768,6 +802,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), entryPoint: entryPoint, + compress: true, resolvedEntryPoint: path.join('nested', entryPoint), single: true, slim: true, @@ -798,6 +833,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), entryPoint: entryPoint, + compress: true, resolvedEntryPoint: entryPoint, single: true, full: true, @@ -826,6 +862,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), entryPoint: entryPoint, + compress: true, resolvedEntryPoint: path.join('nested', entryPoint), single: true, full: true, @@ -872,6 +909,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(bundle => { test.equal(this.globSync.callCount, 8 + listRuleLength); @@ -954,6 +992,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), + compress: true, full: true, }).then(bundle => { test.equal(this.globSync.callCount, 8 + listRuleLength); @@ -1032,6 +1071,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(bundle => { test.equal(this.globSync.callCount, 5 + listRuleLength); @@ -1118,6 +1158,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), + compress: true, full: true, }).then(bundle => { test.equal(this.globSync.callCount, 5 + listRuleLength); @@ -1205,6 +1246,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(bundle => { test.equal(this.globSync.callCount, 6 + listRuleLength); @@ -1289,6 +1331,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), + compress: true, full: true, }).then(bundle => { test.equal(this.globSync.callCount, 6 + listRuleLength); @@ -1381,6 +1424,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, single: true, }).then(bundle => { @@ -1435,6 +1479,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(() => { @@ -1472,6 +1517,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(() => { test.equal(this.readdirSync.callCount, 1); @@ -1493,6 +1539,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then(() => { test.deepEqual(this.project.lastCall.args[0], { @@ -1525,6 +1572,7 @@ exports['deployment.js.tarBundle'] = { deployment.js.tarBundle({ target: path.normalize(target), resolvedEntryPoint: entryPoint, + compress: true, slim: true, }).then((bundle) => { // Extract and inspect the bundle... @@ -1583,7 +1631,8 @@ exports['deploy.findProject'] = { deploy.findProject({ lang: deployment.js, - entryPoint: '~/foo/' + entryPoint: '~/foo/', + compress: true, }); }, @@ -1593,7 +1642,8 @@ exports['deploy.findProject'] = { deploy.findProject({ lang: deployment.js, - entryPoint: target + entryPoint: target, + compress: true, }).then(project => { test.deepEqual(project, { pushdir: fixtures.project,