Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New tests green on pure JS refactor

  • Loading branch information...
commit 8352338175ddffe3dfe4874a0a57bf1b5fe41d6e 1 parent 5157b4d
@deadprogram deadprogram authored
View
17 Makefile
@@ -0,0 +1,17 @@
+BIN := ./node_modules/.bin
+TEST_FILES := test/support/globals.js $(shell find test/specs -type f -name "*.js")
+
+# Our 'phony' make targets (don't involve any file changes)
+.PHONY: test bdd lint
+
+# Run Mocha, with standard reporter.
+test:
+ @$(BIN)/mocha -r cylon --colors $(TEST_FILES)
+
+# Run Mocha, with more verbose BDD reporter.
+bdd:
+ @$(BIN)/mocha -r cylon --colors -R spec $(TEST_FILES)
+
+# Run JSHint
+lint:
+ @$(BIN)/jshint ./lib
View
61 src/adaptor.coffee
@@ -1,61 +0,0 @@
-###
- * cylon crazyflie adaptor
- * http://cylonjs.com
- *
- * Copyright (c) 2013 The Hybrid Group
- * Licensed under the Apache 2.0 license.
-###
-
-'use strict'
-
-require 'cylon'
-require './commands'
-
-Aerogel = require 'aerogel'
-namespace = require 'node-namespace'
-
-namespace "Cylon.Adaptors", ->
- class @Crazyflie extends Cylon.Adaptor
- constructor: (opts = {}) ->
- super
- @aerogelDriver = new Aerogel.CrazyDriver()
- @aerogelDriver.radio = new Aerogel.CrazyRadio()
- @copter = new Aerogel.Copter(@aerogelDriver)
- @connector = @copter
- @proxyMethods Cylon.Crazyflie.Commands, @copter, this
-
- commands: ->
- Cylon.Crazyflie.Commands
-
- connect: (callback) ->
- Logger.info "Connecting to Crazyflie '#{@name}' on port '#{@connection.port}'..."
- port = @connection.port.toString()
- Logger.info port
- if port is "none"
- @connectFirstCopter(callback)
- else
- @doConnect(port, callback)
-
- doConnect: (port, callback) ->
- @copter.connect(port).then ->
- (callback)(null)
- @connection.emit 'connect'
-
- disconnect: ->
- Logger.info "Disconnecting from Crazyflie '#{@name}'..."
- @copter.shutdown()
-
- setParam: (param, value) ->
- @copter.driver.parameters.set(param, value)
-
- connectFirstCopter: (callback) ->
- @aerogelDriver.findCopters().then (copters) ->
- if copters.length is 0
- console.error('No copters found! Is your copter turned on?');
- process.exit(1)
- else
- @doConnect(copters[0], callback)
-
- findCopters: (callback) ->
- @aerogelDriver.findCopters().then (copters) ->
- return (callback)(copters);
View
32 src/commands.coffee
@@ -1,32 +0,0 @@
-###
- * cylon crazyflie commands
- * http://cylonjs.com
- *
- * Copyright (c) 2013 The Hybrid Group
- * Licensed under the Apache 2.0 license.
-###
-
-'use strict'
-
-namespace = require 'node-namespace'
-
-namespace "Cylon.Crazyflie", ->
- @Commands = [
-
- # Public: Initiates take off sequence.
- #
- # Returns nil
- 'takeoff',
-
- # Public: Initiates a landing sequence.
- #
- # Returns nil
- 'land',
- 'hover',
- 'setPitch',
- 'setYaw',
- 'setThrust',
- 'shutdown',
- 'setParam',
- 'findCopters'
- ]
View
26 src/cylon-crazyflie.coffee
@@ -1,26 +0,0 @@
-###
- * cylon-crazyflie
- * http://cylonjs.com
- *
- * Copyright (c) 2013 The Hybrid Group
- * Licensed under the Apache 2.0 license.
-###
-
-require 'cylon'
-require './commands'
-require './adaptor'
-require './driver'
-
-module.exports =
- adaptor: (args...) ->
- new Cylon.Adaptors.Crazyflie(args...)
-
- driver: (args...) ->
- new Cylon.Drivers.Crazyflie(args...)
-
- register: (robot) ->
- Logger.info "Registering Crazyflie adaptor for #{robot.name}"
- robot.registerAdaptor 'cylon-crazyflie', 'crazyflie'
-
- Logger.info "Registering Crazyflie driver for #{robot.name}"
- robot.registerDriver 'cylon-crazyflie', 'crazyflie'
View
38 src/driver.coffee
@@ -1,38 +0,0 @@
-###
- * cylon crazyflie driver
- * http://cylonjs.com
- *
- * Copyright (c) 2013 The Hybrid Group
- * Licensed under the Apache 2.0 license.
-###
-
-'use strict'
-
-require './cylon-crazyflie'
-
-namespace = require 'node-namespace'
-
-namespace "Cylon.Drivers", ->
- class @Crazyflie extends Cylon.Driver
- constructor: (opts = {}) ->
- super
- @proxyMethods Cylon.Crazyflie.Commands, @connection, this
-
- commands: ->
- Cylon.Crazyflie.Commands
-
- # Public: Stops the driver
- #
- # Returns null.
- stop: ->
- Logger.info "#{@device.name} stopped"
- @connection.disconnect()
-
- # Public: Sets a param for the driver
- #
- # param - params
- # value - params
- #
- # Returns null.
- setParam: (param, value) ->
- @connection.setParam(param, value)
View
59 test/specs/adaptor.spec.js
@@ -1,32 +1,33 @@
-(function() {
- 'use strict';
- source('adaptor');
+"use strict";
- describe('Cylon.Adaptors.Crazyflie', function() {
- var crazyflie;
- crazyflie = new Cylon.Adaptors.Crazyflie;
- it("exposes a 'commands' method exposing all available commands", function() {
- return expect(crazyflie.commands()).to.be.eql(Cylon.Crazyflie.Commands);
- });
- it("exposes a 'connect' method to connect to the Crazyflie", function() {
- return expect(crazyflie.connect).to.be.a('function');
- });
- it("exposes a 'disconnect' method to disconnect from the Crazyflie", function() {
- return expect(crazyflie.disconnect).to.be.a('function');
- });
- return it("proxies parameter setting via #setParam", function() {
- var spy;
- spy = sinon.spy();
- crazyflie.copter = {
- driver: {
- parameters: {
- set: spy
- }
- }
- };
- crazyflie.setParam("testing", "true");
- return assert(spy.calledWith("testing", "true"));
- });
+source('adaptor');
+
+describe('Cylon.Adaptors.Crazyflie', function() {
+ var crazyflie = new Cylon.Adaptors.Crazyflie;
+
+ it("exposes a 'commands' method exposing all available commands", function() {
+ expect(crazyflie.commands()).to.be.eql(Cylon.Crazyflie.Commands);
+ });
+
+ it("exposes a 'connect' method to connect to the Crazyflie", function() {
+ expect(crazyflie.connect).to.be.a('function');
});
-}).call(this);
+ it("exposes a 'disconnect' method to disconnect from the Crazyflie", function() {
+ expect(crazyflie.disconnect).to.be.a('function');
+ });
+
+ it("proxies parameter setting via #setParam", function() {
+ var spy;
+ spy = sinon.spy();
+ crazyflie.copter = {
+ driver: {
+ parameters: {
+ set: spy
+ }
+ }
+ };
+ crazyflie.setParam("testing", "true");
+ assert(spy.calledWith("testing", "true"));
+ });
+});
View
28 test/specs/commands.spec.js
@@ -1,19 +1,15 @@
-(function() {
- 'use strict';
- source('commands');
+"use strict";
- describe('Cylon.Crazyflie.Commands', function() {
- return it('is an array of string commands', function() {
- var command, _i, _len, _ref, _results;
- expect(Cylon.Crazyflie.Commands).to.be.a('array');
- _ref = Cylon.Crazyflie.Commands;
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- command = _ref[_i];
- _results.push(expect(command).to.be.a('string'));
- }
- return _results;
- });
+source('commands');
+
+describe('Cylon.Crazyflie.Commands', function() {
+ it('is an array of string commands', function() {
+ var commands = Cylon.Crazyflie.Commands;
+
+ for (var i = 0; i < commands.length; i++) {
+ var command = commands[i];
+ expect(command).to.be.a('string');
+ }
});
+});
-}).call(this);
View
60 test/specs/cylon-crazyflie.spec.js
@@ -1,50 +1,20 @@
-(function() {
- 'use strict';
- var crazyflie, namespace;
+"use strict";
- namespace = require('node-namespace');
+var namespace = require('node-namespace'),
+ crazyflie = source("cylon-crazyflie");
- crazyflie = source("cylon-crazyflie");
+describe("Cylon.Crazyflie", function() {
+ it("can register the adaptor and driver", function() {
+ crazyflie.register.should.be.a('function');
+ });
- describe("Cylon.Crazyflie", function() {
- it("standard async test", function(done) {
- var bool;
- bool = false;
- bool.should.be["false"];
- setTimeout(function() {
- bool.should.be["false"];
- bool = true;
- return bool.should.be["true"];
- });
- 150;
- setTimeout(function() {
- bool.should.be["true"];
- return done();
- });
- return 300;
- });
- it("standard sync test", function() {
- var data, obj;
- data = [];
- obj = {
- id: 5,
- name: 'test'
- };
- data.should.be.empty;
- data.push(obj);
- data.should.have.length(1);
- data[0].should.be.eql(obj);
- return data[0].should.be.equal(obj);
- });
- it("can register", function() {
- return crazyflie.register.should.be.a('function');
- });
- it("can create adaptor", function() {
- return crazyflie.adaptor.should.be.a('function');
- });
- return it("can create driver", function() {
- return crazyflie.driver.should.be.a('function');
- });
+ it("can create adaptor", function() {
+ crazyflie.adaptor.should.be.a('function');
+ expect(crazyflie.adaptor()).to.be.a('object');
});
-}).call(this);
+ it("can create driver", function() {
+ crazyflie.driver.should.be.a('function');
+ expect(crazyflie.driver({ device: {} })).to.be.a('object');
+ });
+});
View
46 test/specs/driver.spec.js
@@ -1,27 +1,25 @@
-(function() {
- 'use strict';
- source("driver");
+"use strict";
- describe('Cylon.Drivers.Crazyflie', function() {
- var crazyflie;
- crazyflie = new Cylon.Drivers.Crazyflie({
- device: {}
- });
- it("exposes a 'commands' method exposing all available commands", function() {
- return expect(crazyflie.commands()).to.be.eql(Cylon.Crazyflie.Commands);
- });
- it("exposes a 'stop' method to disconnect from the Crazyflie", function() {
- return expect(crazyflie.stop).to.be.a('function');
- });
- return it("exposes a 'setParam' method to proxy to the connection", function() {
- var spy;
- spy = sinon.spy();
- crazyflie.connection = {
- setParam: spy
- };
- crazyflie.setParam("testing", "true");
- return assert(spy.calledWith("testing", "true"));
- });
+source('driver');
+
+describe('Cylon.Drivers.Crazyflie', function() {
+ var crazyflie = new Cylon.Drivers.Crazyflie({ device: {} });
+
+ it("exposes a 'commands' method exposing all available commands", function() {
+ expect(crazyflie.commands()).to.be.eql(Cylon.Crazyflie.Commands);
});
-}).call(this);
+ it("exposes a 'stop' method to disconnect from the Crazyflie", function() {
+ expect(crazyflie.stop).to.be.a('function');
+ });
+
+ it("exposes a 'setParam' method to proxy to the connection", function() {
+ var spy;
+ spy = sinon.spy();
+ crazyflie.connection = {
+ setParam: spy
+ };
+ crazyflie.setParam("testing", "true");
+ assert(spy.calledWith("testing", "true"));
+ });
+});
View
5 test/support/globals.js
@@ -8,6 +8,9 @@ var path = require('path');
var chai = require('chai');
var sinonChai = require('sinon-chai');
+require('cylon');
+Logger.setup(false) // disable Cylon's logger for tests
+
global.chai = chai;
global.should = chai.should();
global.expect = chai.expect;
@@ -19,7 +22,7 @@ global.sinon = require('sinon');
// relative to the base path (where the Gruntfile.js also lives)
global.source = function (src) {
console.log('source loading: ' + src)
- var resource = path.normalize('../../dist/' + src);
+ var resource = path.normalize('../../lib/' + src);
return require(resource);
};
View
2  test/support/runner.js
@@ -8,7 +8,7 @@ var Mocha = require('mocha');
var mocha = new Mocha({ reporter: 'spec', ui: 'bdd'});
function run(cb) {
- var files = grunt.file.expand(__dirname + '/../dist/**/*.spec.js');
+ var files = grunt.file.expand(__dirname + '/../**/*.spec.js');
console.log(files)
files.forEach(function (file) {
mocha.addFile(file);
Please sign in to comment.
Something went wrong with that request. Please try again.