1 | 'use strict';
|
2 |
|
3 | var test = require('tap').test
|
4 | , Queue = require('../lib/queue')
|
5 | , EventEmitter = require('events').EventEmitter
|
6 | ;
|
7 |
|
8 | test("command queue", function (t) {
|
9 | t.plan(5);
|
10 |
|
11 | var verifiers = [
|
12 | function (command) {
|
13 | t.deepEqual(command, {rotorSpeed : 10}, "rotor turned on at 10");
|
14 | },
|
15 | function (command) {
|
16 | t.deepEqual(command, {rotorSpeed : 10, pitch : -3}, "pitch altered left");
|
17 | },
|
18 | function (command) {
|
19 | t.deepEqual(command, {rotorSpeed : 10}, "rotor speed maintained");
|
20 | },
|
21 | function (command) {
|
22 | t.deepEqual(command, {rotorSpeed : 10, pitch : 4}, "pitch altered right");
|
23 | },
|
24 | function (command) {
|
25 | t.deepEqual(command, {}, "everything shut down");
|
26 | }
|
27 | ];
|
28 |
|
29 | var pass = 0;
|
30 | var mockConnection = {
|
31 | sendCommand : function (command) {
|
32 | verifiers[pass++](command);
|
33 | }
|
34 | };
|
35 |
|
36 | var tq = new Queue(mockConnection);
|
37 |
|
38 | tq.on('end', function () { t.end(); });
|
39 | tq.enqueue({rotorSpeed : 10}, 500);
|
40 | tq.enqueue({rotorSpeed : 10, pitch : -3}, 500);
|
41 | tq.enqueue({rotorSpeed : 10}, 500);
|
42 | tq.enqueue({rotorSpeed : 10, pitch : 4}, 500);
|
43 | tq.enqueue({}, 500);
|
44 | tq.end();
|
45 | });
|