diff --git a/.gitignore b/.gitignore index 35d189f..59e24f1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ registry.json *~ *.log *.heapsnapshot +zetta-runtime-HEAD +zetta-runtime-jscoverage diff --git a/bin/_coverage b/bin/_coverage new file mode 100755 index 0000000..e082483 --- /dev/null +++ b/bin/_coverage @@ -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 + diff --git a/device.js b/device.js new file mode 100644 index 0000000..a08298f --- /dev/null +++ b/device.js @@ -0,0 +1,6 @@ +var uuid = require('node-uuid'); + +var Device = module.exports = function(){ + this.id = uuid.v4(); +}; + diff --git a/machine_config.js b/machine_config.js index bd64e1e..8f20d12 100644 --- a/machine_config.js +++ b/machine_config.js @@ -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); }; diff --git a/package.json b/package.json index 8b38f0d..1f5a088 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..5decd66 --- /dev/null +++ b/test/test.js @@ -0,0 +1,7 @@ +var assert = require('assert'); + +describe('Hello', function() { + it('should be fine. 1==1', function() { + assert.equal(1, 1); + }); +}); diff --git a/zetta.js b/zetta.js index b440495..56abbe0 100644 --- a/zetta.js +++ b/zetta.js @@ -1,5 +1,6 @@ var Logger = require('./logger')(); var Scientist = require('./scientist'); +var Device = require('./device'); var Zetta = {}; @@ -11,4 +12,6 @@ Zetta.configure = function(/* args */) { return Scientist.configure.apply(null,arguments); }; +Zetta.Device = Device; + module.exports = Zetta;