Skip to content

Commit

Permalink
Cleanup tests, purge boards. Fixes gh-827
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Jun 18, 2015
1 parent 504186a commit 1fa4ce2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
42 changes: 35 additions & 7 deletions test/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ var SerialPort = require("./util/mock-serial").SerialPort,
Boards = five.Boards,
Virtual = Board.Virtual,
Repl = five.Repl,
board = new Board({
io: new MockFirmata(),
board;

function newBoard() {
var io = new MockFirmata();
var board = new Board({
io: io,
debug: false,
repl: false
});

io.emit("ready");

return board;
}

exports["Board"] = {
setUp: function(done) {

board = newBoard();

this.replInit = sinon.stub(Repl.prototype, "initialize", function(callback) {
callback();
});
Expand All @@ -28,6 +39,7 @@ exports["Board"] = {
},

tearDown: function(done) {
Board.purge();
this.replInit.restore();
done();
},
Expand Down Expand Up @@ -143,6 +155,7 @@ exports["Board"] = {

exports["Virtual"] = {
setUp: function(done) {
board = newBoard();
this.Board = sinon.stub(five, "Board", function() {});
this.Expander = sinon.stub(five, "Expander", function() {
this.name = "MCP23017";
Expand All @@ -151,6 +164,7 @@ exports["Virtual"] = {
},

tearDown: function(done) {
Board.purge();
this.Board.restore();
this.Expander.restore();
done();
Expand Down Expand Up @@ -245,6 +259,7 @@ exports["Boards"] = {
},

tearDown: function(done) {
Board.purge();
if (this.replInit) {
this.replInit.restore();
}
Expand Down Expand Up @@ -578,6 +593,16 @@ exports["Boards"] = {

exports["instance"] = {

setUp: function(done) {
board = newBoard();
done();
},

tearDown: function(done) {
Board.purge();
done();
},

cache: function(test) {
test.expect(1);
test.ok(_.contains(five.Board.cache, board));
Expand Down Expand Up @@ -613,11 +638,7 @@ exports["instance"] = {
exports["Board.mount"] = {
setUp: function(done) {

this.board = new Board({
io: new MockFirmata(),
debug: false,
repl: false
});
this.board = newBoard();

done();
},
Expand Down Expand Up @@ -658,6 +679,13 @@ exports["Board.mount"] = {
};

exports["bubbled events from io"] = {
setUp: function(done) {
done();
},
tearDown: function(done) {
Board.purge();
done();
},
string: function(test) {
test.expect(1);

Expand Down
20 changes: 12 additions & 8 deletions test/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,8 @@ exports["Pin.isAnalog"] = {

exports["PinShape"] = {
setUp: function(done) {
// Initilize test board
var io = new MockFirmata();

io.emit("ready");

newBoard();
// Pins to test

// default Pin instances passing only the pin number
Expand All @@ -481,6 +478,11 @@ exports["PinShape"] = {
done();
},

tearDown: function(done) {
Board.purge();
done();
},

defaultPinShape: function(test) {
test.expect(23);

Expand Down Expand Up @@ -530,10 +532,7 @@ exports["PinShape"] = {

exports["PinMode"] = {
setUp: function(done) {
// Initilize test board
var io = new MockFirmata();

io.emit("ready");
newBoard();

// Pins to test
this.modeD0 = new Pin({ pin: 4, mode: 0});
Expand All @@ -550,6 +549,11 @@ exports["PinMode"] = {
done();
},

tearDown: function(done) {
Board.purge();
done();
},

specifiedMode: function(test) {
test.expect(10);

Expand Down

0 comments on commit 1fa4ce2

Please sign in to comment.