diff --git a/lib/tessel/commands.js b/lib/tessel/commands.js index 9760a092..a13a8aef 100644 --- a/lib/tessel/commands.js +++ b/lib/tessel/commands.js @@ -9,7 +9,7 @@ module.exports.stopRunningScript = function() { }; module.exports.disablePushedScript = function() { return ['/etc/init.d/tessel-app', 'disable']; -} +}; module.exports.deleteFolder = function(filepath) { return ['rm', '-rf', filepath]; }; diff --git a/lib/tessel/erase.js b/lib/tessel/erase.js index 62657d24..ef576182 100644 --- a/lib/tessel/erase.js +++ b/lib/tessel/erase.js @@ -8,13 +8,13 @@ Tessel.prototype.eraseScript = function() { logs.info('Erasing files from Flash...'); return self.simpleExec(commands.stopRunningScript()) .then(function stopped() { - return self.simpleExec(commands.disablePushedScript()) + return self.simpleExec(commands.disablePushedScript()); }) .then(function disabled() { return self.simpleExec(commands.deleteFolder(Tessel.PUSH_PATH)) .then(function erased() { logs.info('Files erased.'); - }) + }); }) .catch(function(error) { // If we get a notice that the command failed diff --git a/test/unit/erase.js b/test/unit/erase.js index 96a66cd2..27e3a13b 100644 --- a/test/unit/erase.js +++ b/test/unit/erase.js @@ -27,20 +27,27 @@ exports['Tessel.prototype.erase'] = { eraseAsUsual: function(test) { var self = this; - test.expect(3); + test.expect(10); + + var expected = [commands.stopRunningScript(), commands.disablePushedScript(), commands.deleteFolder(Tessel.PUSH_PATH)]; + var commandNumber = 0; // Test that we received the proper command - self.tessel._rps.once('control', function(command) { + self.tessel._rps.on('control', function(command) { var receivedCommands = command.toString().split(' '); - var expected = commands.stopRunningScript(); // Test that the command has the proper number of args - test.equal(receivedCommands.length, expected.length); + test.equal(receivedCommands.length, expected[commandNumber].length); // And the proper args in each place for (var i = 0; i < receivedCommands.length; i++) { - test.equal(receivedCommands[i], expected[i]); + test.equal(receivedCommands[i], expected[commandNumber][i]); } + commandNumber++; + + setImmediate(function() { + self.tessel._rps.emit('close'); + }); }); self.tessel.eraseScript() @@ -51,10 +58,6 @@ exports['Tessel.prototype.erase'] = { .catch(function() { test.fail('Error thrown on proper flash erase'); }); - - setImmediate(function() { - self.tessel._rps.emit('close'); - }); }, noCodeInFlash: function(test) {