Skip to content

Commit

Permalink
Merge pull request #2 from zettajs/device-updates
Browse files Browse the repository at this point in the history
Device updates, Tests, Test Coverage
  • Loading branch information
mdobson committed Jun 24, 2014
2 parents 3a09824 + 195640d commit 6aa4fd3
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ registry.json
*~
*.log
*.heapsnapshot
zetta-runtime-HEAD
zetta-runtime-jscoverage
21 changes: 21 additions & 0 deletions bin/_coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

if [ $(which jscoverage) ]
then
echo "Running test coverage..."
rm -rf ./zetta-runtime-HEAD
rm -rf ./zetta-runtime-jscoverage
git archive --format=tar --prefix=zetta-runtime-HEAD/ HEAD | tar x
jscoverage --exclude=node_modules ./zetta-runtime-HEAD ./zetta-runtime-jscoverage
cd ./zetta-runtime-jscoverage/
npm install
mocha --reporter html-cov > coverage.html
open coverage.html
else
echo "jscoverage is not installed"
echo "if on OS X:"
echo " use brew install jscoverage"
echo "if on linux:"
echo " use sudo apt-get install jscoverage"
fi

6 changes: 6 additions & 0 deletions device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var uuid = require('node-uuid');

var Device = module.exports = function(){
this.id = uuid.v4();
};

18 changes: 18 additions & 0 deletions machine_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ MachineConfig.prototype.call = function(/* type, ...args */) {
}
};

MachineConfig.prototype.monitor = function(queueName) {
var propName = queueName;

queueName = this.machine.type + '/' + this.properties.id + '/' + propName;

this.machine.streams.push(queueName);

Object.defineProperty(this.machine, propName, {
get: function(){
return this.machine.properties[propName];
},
set: function(newValue){
pubsub.publish(queueName, newValue);
this.machine.properties[propName] = newValue;
}
});
};

MachineConfig.create = function(machine) {
return new MachineConfig(machine);
};
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
"spdy": "~1.25.1",
"titan": "~0.1.1",
"strftime": "~0.8.0",
"ws": "^0.4.31"
"ws": "^0.4.31",
"node-uuid": "^1.4.1"
},
"devDependencies": {
"mocha": "^1.20.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha",
"coverage":"bin/_coverage"
},
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var assert = require('assert');

describe('Hello', function() {
it('should be fine. 1==1', function() {
assert.equal(1, 1);
});
});
3 changes: 3 additions & 0 deletions zetta.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Logger = require('./logger')();
var Scientist = require('./scientist');
var Device = require('./device');

var Zetta = {};

Expand All @@ -11,4 +12,6 @@ Zetta.configure = function(/* args */) {
return Scientist.configure.apply(null,arguments);
};

Zetta.Device = Device;

module.exports = Zetta;

0 comments on commit 6aa4fd3

Please sign in to comment.