Permalink
Browse files

Tests: Move extended/*.js to own grunt task

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information...
1 parent f49810f commit 3489091b64d09d3a73b8b29c6357f3ae384fd1ff @rwaldron committed Dec 12, 2016
Showing with 25 additions and 131 deletions.
  1. +2 −4 Gruntfile.js
  2. +2 −0 test/extended/animation.js
  3. +7 −52 test/extended/led.js
  4. +2 −0 test/extended/piezo.js
  5. +12 −75 test/extended/servo.js
View
@@ -217,10 +217,7 @@ module.exports = function(grunt) {
// Support running a complete set of tests with
// extended (possibly-slow) tests included.
grunt.registerTask("nodeunit:complete", function() {
- var testConfig = grunt.config("nodeunit.tests");
- testConfig.push("test/extended/*.js");
- grunt.config("nodeunit.tests", testConfig);
- grunt.task.run("nodeunit");
+ console.log("\nDid you mean? 'grunt nodeunit:extended' ?");
});
grunt.registerTask("nodeunit:extended", function() {
@@ -230,6 +227,7 @@ module.exports = function(grunt) {
"test/extended/piezo.js",
"test/extended/servo.js",
]);
+
grunt.task.run("nodeunit");
});
@@ -1,3 +1,5 @@
+require("../common/bootstrap");
+
exports["Animation"] = {
setUp: function(done) {
this.board = newBoard();
View
@@ -1,3 +1,5 @@
+require("../common/bootstrap");
+
exports["Led - PWM"] = {
setUp: function(done) {
this.board = newBoard();
@@ -10,63 +12,19 @@ exports["Led - PWM"] = {
board: this.board
});
- this.proto = [{
- name: "on"
- }, {
- name: "off"
- }, {
- name: "toggle"
- }, {
- name: "brightness"
- }, {
- name: "pulse"
- }, {
- name: "fade"
- }, {
- name: "fadeIn"
- }, {
- name: "fadeOut"
- }, {
- name: "strobe"
- }, {
- name: "blink"
- }, {
- name: "stop"
- }];
-
- this.instance = [{
- name: "id"
- }, {
- name: "pin"
- }, {
- name: "value"
- }];
-
done();
},
tearDown: function(done) {
- Board.purge();
- this.sandbox.restore();
- if (this.led.animation) {
+ if (this.led && this.led.animation) {
this.led.animation.stop();
}
+ Board.purge();
+ Led.purge();
+ this.sandbox.restore();
done();
},
- shape: function(test) {
- test.expect(this.proto.length + this.instance.length);
-
- this.proto.forEach(function(method) {
- test.equal(typeof this.led[method.name], "function");
- }, this);
-
- this.instance.forEach(function(property) {
- test.notEqual(typeof this.led[property.name], "undefined");
- }, this);
-
- test.done();
- },
pulse: function(test) {
var renderSpy = this.sandbox.spy(this.led, "@@render");
@@ -248,7 +206,7 @@ exports["Led - PWM"] = {
},
autoMode: function(test) {
- test.expect(4);
+ test.expect(3);
this.led.mode = 1;
this.led.brightness(255);
@@ -262,9 +220,6 @@ exports["Led - PWM"] = {
this.led.fade();
test.equal(this.led.mode, 3);
- this.led.strobe();
- test.equal(this.led.mode, 3);
-
test.done();
}
@@ -1,3 +1,5 @@
+require("../common/bootstrap");
+
exports["Piezo"] = {
setUp: function(done) {
@@ -1,91 +1,30 @@
-var MockFirmata = mocks.Firmata;
-var five = require("../../lib/johnny-five.js");
-var sinon = require("sinon");
-var Board = five.Board;
-var Servo = five.Servo;
-
-function newBoard() {
- var io = new MockFirmata();
- var board = new Board({
- io: io,
- debug: false,
- repl: false
- });
-
- io.emit("ready");
-
- return board;
-}
+require("../common/bootstrap");
exports["Servo"] = {
setUp: function(done) {
-
this.board = newBoard();
-
- this.servoWrite = sinon.spy(this.board.io, "servoWrite");
-
- this.proto = [{
- name: "to"
- }, {
- name: "step"
- }, {
- name: "move"
- }, {
- name: "min"
- }, {
- name: "max"
- }, {
- name: "center"
- }, {
- name: "sweep"
- }, {
- name: "stop"
- }, {
- name: "clockWise"
- }, {
- name: "cw"
- }, {
- name: "counterClockwise"
- }, {
- name: "ccw"
- }, {
- name: "write"
- }];
-
- this.instance = [{
- name: "id"
- }, {
- name: "pin"
- }, {
- name: "mode"
- }, {
- name: "range"
- }, {
- name: "invert"
- }, {
- name: "type"
- }, {
- name: "interval"
- }, {
- name: "value"
- }];
+ this.sandbox = sinon.sandbox.create();
+ this.servoWrite = this.sandbox.spy(MockFirmata.prototype, "servoWrite");
done();
},
tearDown: function(done) {
- Board.purge();
- if (this.servo.animation) {
+ if (this.servo && this.servo.animation) {
this.servo.animation.stop();
}
- this.servoWrite.restore();
+
+ Board.purge();
+ Servo.purge();
+ this.sandbox.restore();
+
done();
},
center: function(test) {
- test.expect(5);
+ test.expect(4);
- this.spy = sinon.spy(Servo.prototype, "center");
+ this.spy = this.sandbox.spy(Servo.prototype, "center");
this.servo = new Servo({
pin: 11,
@@ -96,10 +35,10 @@ exports["Servo"] = {
// constructor called .center()
test.ok(this.spy.called);
+
// and servo is actually centered
test.equal(this.servo.position, 90);
- this.spy.restore();
this.servo.to(180);
this.servo.center(1000, 100);
@@ -111,10 +50,8 @@ exports["Servo"] = {
// it fired a move:complete event when finished
this.servo.on("move:complete", function() {
test.equal(this.servo.position, 90);
- test.ok(1, "event fired");
test.done();
}.bind(this));
-
},
min: function(test) {

0 comments on commit 3489091

Please sign in to comment.