Skip to content

Commit

Permalink
Updates tests to make sure all proper erase commands are called
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Oct 2, 2015
1 parent e0e8b69 commit aa0f5b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/tessel/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
Expand Down
4 changes: 2 additions & 2 deletions lib/tessel/erase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions test/unit/erase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit aa0f5b1

Please sign in to comment.