Skip to content

Commit

Permalink
Minor property qualifier fix + missing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Apr 5, 2018
1 parent e1ca0a7 commit f12ca34
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/firmata.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ function Board(port, options, callback) {
},
};

if (options.bufferSize) {
options.highWaterMark = options.bufferSize;
if (options.serialport && options.serialport.bufferSize) {
options.serialport.highWaterMark = options.serialport.bufferSize;
}

var settings = Object.assign({}, defaults, options);
Expand Down
36 changes: 36 additions & 0 deletions test/unit/firmata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,19 @@ describe("Board: lifecycle", function() {
done();
});

it("aliases serialport defaults for backward compatibility", function(done) {
var a = new Board("/path/to/fake/usb1", {
serialport: {
highWaterMark: 1028,
bufferSize: 1
}
}, initNoop);

assert.deepEqual(transport.spy.getCall(0).args[1].highWaterMark, 1);

done();
});

it("uses default baud rate and buffer size", function(done) {
var port = "fake port";
var board = new Board(port, function(err) {});
Expand Down Expand Up @@ -924,6 +937,29 @@ describe("Board: lifecycle", function() {
transport.emit("error");
});

it("When reportVersion and queryFirmware timeout, call noop", function(done) {
this.timeout(50);
sandbox.stub(Board.prototype, "reportVersion");
sandbox.stub(Board.prototype, "queryFirmware");
var clock = sandbox.useFakeTimers();
var transport = new SerialPort("/path/to/fake/usb");
var opt = {
reportVersionTimeout: 1
};
var board = new Board(transport, opt, initNoop);
board.versionReceived = false;

clock.tick(2);

assert.equal(board.reportVersion.callCount, 1);
assert.equal(board.queryFirmware.callCount, 1);

assert.equal(board.reportVersion.getCall(0).args[0](), undefined);
assert.equal(board.queryFirmware.getCall(0).args[0](), undefined);

done();
});

it("sends 'REPORT_VERSION' and 'QUERY_FIRMWARE' if it hasnt received the version within the timeout", function(done) {
this.timeout(50000);
var transport = new SerialPort("/path/to/fake/usb");
Expand Down

0 comments on commit f12ca34

Please sign in to comment.