UNPKG

stk500

Version:

Fully javascript stk500v1 programmer. Allows you to program Arduinos straight from node (or browser for that matter). No more avrdude system calls or using the arduino IDE.

55 lines (50 loc) 1.58 kB
var Statics = require('../lib/statics'); var receiveData = require('../lib/receiveData'); var es = require('event-stream'); describe('receiveData', function () { beforeEach(function () { this.port = es.through(function (data) { this.emit('data', data); }); }); it('should receive a matching buffer', function (done) { var inputBuffer = Statics.OK_RESPONSE; receiveData(this.port, 10, inputBuffer.length, function (err, data) { if (err) { return done(err); } Should.not.exist(err); var matched = data.equals(inputBuffer); Should.exist(matched); matched.should.equal(true); done(); }); this.port.write(inputBuffer); }); it('should timeout', function (done) { var inputBuffer = Statics.OK_RESPONSE; receiveData(this.port, 10, inputBuffer.length, function (err, data) { if (err) { err.message.should.equal('receiveData timeout after 10ms'); return done(); } done(new Error('Did not time out')); }); this.port.write(inputBuffer.slice(0, 1)); }); it('should receive a buffer in chunks', function (done) { var inputBuffer = Statics.OK_RESPONSE; receiveData(this.port, 10, inputBuffer.length, function (err, data) { if (err) { return done(err); } Should.not.exist(err); var matched = data.equals(inputBuffer); Should.exist(matched); matched.should.equal(true); done(); }); this.port.write(inputBuffer.slice(0, 1)); this.port.write(inputBuffer.slice(1, 2)); }); });