Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deadprogram/9064253 to your computer and use it in GitHub Desktop.
Save deadprogram/9064253 to your computer and use it in GitHub Desktop.
Test Driver Robotics with Cylon.js

How to install:

You will need to be using the HEAD of the 'tdr' branch of Cylon.js itself.

sudo npm install sinon-chai -g
sudo npm install mocha -g
npm install cylon-firmata

How to run tests:

mocha robot.test.js
var Cylon = require("cylon");
// Initialize the robot
var robot = Cylon.robot({
name: 'testor',
// Change the port to the correct port for your Arduino.
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
device: { name: 'led', driver: 'led', pin: 13 },
work: function(my) {
// we do our thing here
my.led.toggle();
every((1).second(), function() { my.led.toggle(); });
}
});
// start working
robot.start();
"use strict";
process.env['CYLON_TEST'] = true;
var chai = require("chai");
var sinon = require("sinon");
var sinonChai = require("sinon-chai");
chai.should();
chai.use(sinonChai);
var clock = sinon.useFakeTimers();
var Cylon = require('cylon');
require("./robot.js");
describe("robot", function () {
var robot = Cylon.findRobot("testor");
it("should have work", function () {
return robot.work.should.be.a('function');
});
it("should toggle the led after 1 second", function (done) {
var led = robot.devices['led'];
var toggle = sinon.stub(led, 'toggle');
clock.tick((1).second());
toggle.should.have.been.called;
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment