From 5f3e011a03bb3183b7ea08eb0cdda09a251b68f9 Mon Sep 17 00:00:00 2001 From: Matt Dobson Date: Mon, 23 Jun 2014 21:56:43 -0400 Subject: [PATCH 1/2] Added some functionality to machine_config for monitor statements. Added to the gitignore for tests and test coverage. --- .gitignore | 2 ++ machine_config.js | 18 ++++++++++++++++++ package.json | 10 +++++++--- zetta.js | 3 +++ 4 files changed, 30 insertions(+), 3 deletions(-) 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/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/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; From 195640d0706a16cb0e9f76a035918a88b27c05ab Mon Sep 17 00:00:00 2001 From: Matt Dobson Date: Mon, 23 Jun 2014 21:58:15 -0400 Subject: [PATCH 2/2] Added configuration for mocha tests. Added configuration for test coverage. Added a device base class. --- bin/_coverage | 21 +++++++++++++++++++++ device.js | 6 ++++++ test/test.js | 7 +++++++ 3 files changed, 34 insertions(+) create mode 100755 bin/_coverage create mode 100644 device.js create mode 100644 test/test.js 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/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); + }); +});